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.

CommentFileSizeAuthor
#1 search-tab-weight-1762848-1.patch2.81 KBcoredumperror
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

coredumperror’s picture

Title: Change search tab order? » Modules implementing hook_search_info() cannot specify the weight of their search page tab
Category: support » feature
FileSize
2.81 KB

After 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 for hook_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 because search_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.

heddn’s picture

An easy way to adjust the search tab order is with hook_menu_alter(). The example below moves example last in the list.

function example_menu_alter(&$items) {
  //Need to list the menu items twice to fix both search menu items.
  if (!empty($items['search/example'])) {
    $items['search/example']['weight'] = 10;
  }
  if (!empty($items['search/example/%menu_tail'])) {
    $items['search/example/%menu_tail']['weight'] = 10;
  }
}
coredumperror’s picture

Version: 7.x-dev » 8.x-dev

Thank 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.

jhodgdon’s picture

Title: Modules implementing hook_search_info() cannot specify the weight of their search page tab » Add ability to set order of search tabs

title update

tim.plunkett’s picture

#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.

jhodgdon’s picture

I 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.

coredumperror’s picture

Yeah, heddn's workaround is good enough for D7, I think. I've been using it on my company's site for a while.

jhodgdon’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)
Related issues: +#2042807: Convert search plugins to use a ConfigEntity and a PluginBag

That 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).