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
[DX] Add direction to backdrop_sort() #2149
Comments
This sounds useful to be able to sort in either direction. The code could be more concise (having PHP already has constants for sort order: |
I just thought of this in #449 (comment), but in the mean time even without this parameter we can just |
Pushed PR to see if Travis/Zen would complain. Looked like they're ok. But this hasn't been tested at all. Looks like we don't have particular tests for this function AFAICT. |
Yeah a |
Is this still a candidate for 1.5? Looks like #449 got in without it, so moving to 1.x-future |
So here's a curious thing: Tests failed on PHP 7, and I thought they might. The test used an array which has 3 items with the same weight. I did this so we could test sorting by multiple keys ('weight' and 'info'), which worked fine. However, if sorting by weight alone that gives us a bit of a problem, because apparently Here's the array (note three items with weight = 1):
I actually expected the sort by weight to give the order (for the weight = 1 items):
i.e fall back to sort alphabetical by the parent array keys (I guessed), but PHP5 insisted that it was:
So I built the tests with this as the expected result (cheating, I know). But behold, PHP7 says it should be:
"Undefined" indeed! So long post, coming to an end. Should I just build a test which avoids identical keys? Or do we need some way of making Thoughts @quicksketch? |
My take on this is that we should just use PHP's sorting on this, so identical keys cannot be counted on to produce consistent results. FormAPI does some fancy stuff where it adds "microweights" to everything before the sorting is done, e.g. it makes |
Another concern: What can we do about sorts that might want to have in different directions? e.g. I want to sort by "weight" DESC but "title" ASC? And to be clear on this question:
Yes. |
I thought I was going to need this on the status report. In the end though I ended up making my own order instead of using a sort. |
Hadnt thought of that. This would be necessarily a bit verbose:
|
It wouldnt be possible to do multiple-direction sorts without an API change, so cant do it. And incidentally, should have mentioned I had already re-built the tests with non-identical keys, and tests pass. |
Descoping for 1.7 since we are 4 days from release. |
Looks like this could use a code review (and a rebase) if we want to get it in for 1.8. We're two weeks from code freeze. |
No action on this one, bumping milestone. |
There may be a solution to this: make the $sort parameter take either the constants ( e.g.
Or just
Which should have the same result (keys not specified use However, we can add that as a later enhancement while making the current PR's API backwards-compatible. Let's go ahead and merge what we have and make a new issue for adding multi-directional sorting. |
If tests are fully passing we can get this in today. |
I've merged in backdrop/backdrop#1535. While this is after feature freeze, the code had been ready long before freeze and all tests had been passing. And it's a minor addition they only expands one function. There was no impact here to any existing code. So I apologize for merging something after freeze, but I hope it's excusable in this case. |
Was trying to build a
tablesort
table without a database query which required sorting an array. Works fine withbackdrop_sort()
but only for one click of the header, as this function has no sense of direction. Hackingcommon.inc
works (I only changed the clause for single key, couldnt manage the multiple-key recursive wizardry) but not sure the implications.Thoughts?
PR by @docwilmot backdrop/backdrop#1535
The text was updated successfully, but these errors were encountered: