Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
This is a regression introduced in #3062573: The menus are sorted by machine name and not by label
The website encountered an unexpected error. Please try again later.
Error: Undefined class constant 'MAX_BUNDLE_NUMBER' in Drupal\admin_toolbar_tools\SearchLinks->getLinks() (line 185 of modules/contrib/admin_toolbar/admin_toolbar_tools/src/SearchLinks.php).
Drupal\admin_toolbar_tools\SearchLinks->getLinks() (Line: 289)
Drupal\admin_toolbar_tools\Controller\ToolbarController->search()
Proposed resolution
same constant should be used in ExtraLinks.php and SearchLinks.php
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#9 | 3065013-9.patch | 6.54 KB | oknate |
| |||
#9 | interiff-3065013-8-9.txt | 3.9 KB | oknate |
#8 | 3065013-8.patch | 5.01 KB | oknate |
| |||
#7 | 3065013-7.patch | 4.75 KB | oknate |
| |||
#7 | 3065013--interdiff-6-7.txt | 1.96 KB | oknate |
Comments
Comment #2
oknateHere's a fix. We should have test coverage so this doesn't happen again. I'll see if I can set that up.
Comment #3
oknateTest only patch that demonstrates the bug.
Comment #4
oknateCombining the test coverage with the fix. The test coverage is very minimal. I'd like to expand test coverage of menus in search.
UPDATE: I'm adding additional test coverage below.
Comment #6
oknateAdding additional test coverage for menus in the admin_toolbar.search route.
Comment #7
oknate1) removing "Ava", I'm noticing this is showing up in both the admin toolbar and in the search links. I'm looking into that.
2) alphabetizing the names used for creating menus in the test.
Comment #8
oknateI figured why "Ava" was showing in both the toolbar and the search links. We were missing a use statement that meant that sort wasn't working properly in the SearchLinks.php class:
It took me a while to figure out why I was not getting the expected output. Finally, I ran this code:
in ExtraLinks.php:
Array ( [0] => ada [1] => admin [2] => amara [3] => amelia [4] => arabella [5] => asher [6] => astrid [7] => atticus [8] => aurora [9] => ava )
in SearchLinks.php:
Array ( [0] => account [1] => ada [2] => admin [3] => amara [4] => amelia [5] => arabella [6] => asher [7] => astrid [8] => atticus [9] => aurora )
So it was the sorting that was breaking. At first I thought maybe it was an issue with the offset, but I tested and our use of offset is correct.
Comment #9
oknateAdding test coverage for the same two arrays of menus within the toolbar. Asserting that links after the first 10 don't appear, and the the first 10 do appear.
Comment #10
adriancidThe patch fail to apply, we don't have this line in the dev branch.
Comment #11
oknateHmm. Taking another look. I see:
on line 185 of SearchLinks.php in the 8.x-2.x-dev branch, which is a problem because that constant doesn't exist. I had copied it from ExtraLinks.php and forgot that I had changed the constant name in that class.
Can you check again? If we didn't have that line, how would the patches above apply when running the automated tests?
Comment #12
oknateComment #14
adriancidSorry, I just forgot to made git pull, as I'm working in another laptop now :-D
Comment #15
oknateNo problem, thanks for helping me fix the regression I introduced!
Comment #16
oknateFew people are using the 8.x-2.x branch yet. I only caught it because I was testing how another module works with admin_toolbar 8.x-2.x-dev installed.
But now we have a bit more test coverage, so hopefully it will prevent regressions for the search feature.
Comment #17
adriancidThanks for your help on this module @oknate