How to change menu tab menu MENU_LOCAL_TASK in Drupal

I created a tab menu in my custom Drupal 6 module. I want to place the html drop-down list to the right of the tab menu at the top of my module page. Some ajax events will be activated in the list upon change, for example. Changing the LIMIT clause in an SQL query by setting 10,20,50,100 results. How can I achieve this in Drupal without hacking templates?

Thanks,

+4
source share
2 answers

You can do this by overriding theme_menu_local_tasks() in your theme:

 function yourTheme_menu_local_tasks() { // Prepare empty dropdown to allow for unconditional addition to output below $dropdown = ''; // Check if the dropdown should be added to this menu $inject_dropdown = TRUE; // TODO: Add checking logic according to your needs, eg by inspecting the path via arg() // Injection wanted? if ($inject_dropdown) { // Yes, build the dropdown using Forms API $select = array( '#type' => 'select', '#title' => t('Number of results:'), '#options' => array('10', '20', '50', '100'), ); // Wrap rendered select in <li> tag to fit within the rest of the tabs list $dropdown = '<li>' . drupal_render($select) . '</li>'; } // NOTE: The following is just a copy of the default theme_menu_local_tasks(), // with the addition of the (possibly empty) $dropdown variable output $output = ''; if ($primary = menu_primary_local_tasks()) { $output .= "<ul class=\"tabs primary\">\n". $primary . $dropdown . "</ul>\n"; } if ($secondary = menu_secondary_local_tasks()) { $output .= "<ul class=\"tabs secondary\">\n". $secondary ."</ul>\n"; } return $output; } 

(NOTE: unverified code - potential typos)

+6
source

Since you mean the code to be placed in the module, then the module should implement hook_theme_registry_alter() , which will allow the module to override the theme_menu_local_tasks() function. The module must save the value of the previous callback so that it can still call it if the page is not the one it should change.
Implementing a hook in a module allows you to have the usual menu tabs when the module is disabled; changing the current theme will require you to change it when you want more functionality, and if you use a theme made by another person, you must change the theme all the time when you download the new version. If you use more than one theme, then you must make changes to each theme used.
In the general case, the modification of the topic required from the module should be done inside the module.

0
source

All Articles