Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ordering@' => 0 does not work #33

Open
drzraf opened this issue Apr 29, 2022 · 2 comments · May be fixed by #34
Open

'ordering@' => 0 does not work #33

drzraf opened this issue Apr 29, 2022 · 2 comments · May be fixed by #34

Comments

@drzraf
Copy link
Contributor

drzraf commented Apr 29, 2022

... because

if ($location) {

keeps $order from being set if the location is 0 because the conditional does not distinguish between 0 and the empty string.

@drzraf
Copy link
Contributor Author

drzraf commented Apr 29, 2022

As a consequence we can't order as the first element.
Documentation (https://learn.getgrav.org/17/forms/blueprints/advanced-features#changing-field-ordering) states that -1 should be used.

But using -1 triggers this:

if ((string)(int)$ordering === (string)$ordering) {
$location = array_search($item, $reordered, true) ?: 0;
$rel = array_splice($reordered, $location, 1);
array_splice($reordered, $ordering, 0, $rel);

... which, as expected by https://www.php.net/manual/en/function.array-splice.php put the extracted element at the end of the list.

@drzraf
Copy link
Contributor Author

drzraf commented Apr 29, 2022

My suggestion is to not drop explicit 0 value. A quick way is changing line 438 by
if ($location || $location === 0) {

drzraf pushed a commit to drzraf/toolbox that referenced this issue Apr 29, 2022
drzraf pushed a commit to drzraf/toolbox that referenced this issue Sep 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant