Problem/Motivation
I came across a potentially unexpected sorting outcome for Entity query builder when testing patches for the menu list builder on Drupal 10.2.12 (see related issues).
Sorted results of execute()
function of Drupal/Core/Config/Entity/Query/Query.php
are case sensitive. This result may be mitigated by additional alphabetization later on via display. However, when pagination gets activated, due to the result chunking, lowercase entries can end up being grouped together and not displayed where one would expect them.
Steps to reproduce
- Fresh install of standard Drupal 10/11
- Install of Devel module - enable it and Devel Generate
- Using Devel Generate, create 50 new menus to force pagination of menu list (number of links and other settings per menu do not matter)
- Visit the menu list page (/admin/structure/menu).
- Devel Generate will have created a bunch of uppercase titled menus and the menu list will sort alphabetically as expected
- Manually create a new menu item called 'aardvark' (all lowercase) and save. Revisit the menu list page.
- The 'aardvark' menu should appear on the top of the second page of results, not sorted with the rest of the 'A' items on the first page.
- Manually create additional new menu items called 'echidna' and 'ocelot' (again, all lowercase) and save. Revisit the menu list page.
- The 'echidna' and 'ocelot' menu should appear on the top of the second page of results, grouped with 'aardvark' and not alphabetically sorted as expected.
Proposed resolution
Use strcasecmp()
when comparing strings.
Remaining tasks
Test
Review
Commit
User interface changes
None
Introduced terminology
None
API changes
None
Data model changes
None
Release notes snippet
TBD