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.
I notice that, by default, the tabs that appear on the search page for each module that implements hook_search_info()
(which I believe are menu local tasks?) are sorted in alphabetical order based on their title. Is there a way to change this to some other arbitrary order?
I've been googling and searching the issue queue for a while, but I haven't found a solution.
Comment | File | Size | Author |
---|---|---|---|
#1 | search-tab-weight-1762848-1.patch | 2.81 KB | coredumperror |
Comments
Comment #1
coredumperror CreditAttribution: coredumperror commentedAfter looking further into this, I discovered that the answer to my original question is "No", because of how
search_menu()
is currently written. It adds a hard-coded weight of 0 to every search tab, thus the order cannot be changed.So, I made a quick patch to implement a way for module authors to set their tab's weight alongside the title and path they provide in their implementation of
hook_search_info()
. I included an update to the docstring forhook_search_info()
, though I'm sure it's formatted poorly due to my ignorance of the rules. The "minimum -99 and maximum 99" thing is becausesearch_menu()
now subtracts 200 from the default module's weight (rather than 10 like it did before), so the weight limits are there to insure that the subtraction actually puts the default module first on the non-%menu_tail'd search pages.The real solution to this issue is probably to alter the "Active Search Modules" fieldset on
admin/config/search/settings
to add weight settings, but that's way too complicated (and time consuming) for me to do.Comment #2
heddnAn easy way to adjust the search tab order is with hook_menu_alter(). The example below moves example last in the list.
Comment #3
coredumperror CreditAttribution: coredumperror commentedThank you! This worked quite wonderfully.
I think that my suggestion of adding weights to the Active Search Module fieldset on
admin/config/search/settings
would be an even better solution, though, so I'm going to leave this issue open. Obviously, that kind of change won't be made to Drupal 7, though, so I've changed the version to 8.x-dev.Comment #4
jhodgdontitle update
Comment #5
tim.plunkett#2042807: Convert search plugins to use a ConfigEntity and a PluginBag now converts to using tabledrag to control the order. Once that is actually in, this can just be moved back to D7.
Comment #6
jhodgdonI do not think we will fix it for 7. Feature request. So we can probably close this as "won't fix" if we take care of 8.x on the other issue.
Comment #7
coredumperror CreditAttribution: coredumperror commentedYeah, heddn's workaround is good enough for D7, I think. I've been using it on my company's site for a while.
Comment #8
jhodgdonThat other issue is definitely allowing you to set the order of search tabs, so marking this as a duplicate (since we do not do feature requests in 7 and this is therefore an 8-only issue).