Adding non-menu things to primary links menu items with Drupal 7's page alter hook
The request was to stick search in a menu. I said "I bet that's easy with hook_page_alter()!"
Not quite.
The primary links menu is output directly by the theme, and so is one of the very very few things that occurs after hook_page_alter().
You can tell the theme to stop outputting it directly, and put it in a block that is displayed in a region, or you can add it to the page rendering array in code with hook_page_build().
When exposed this way, as in the usual block system, menu links do in fact show up as wonderful, discrete, modifiable elements that you can stick your own elements of your own into- or drag in the search form to have it rendered there, if you really insist.
Also, when using Devel's kpr() to print something (including when checking off show page alter), Command+F search in your browser does not see text in collapsed elements. At least in Firefox 6. Not sure why, but be warned.
More like this
- Return user to current page: How to link to a form from a Drupal menu
- Building Beauty presentation documentation and links
- Why isn't Drupal's one run-time menu item altering hook getting run?
- Have menu local tasks (view, edit, etc. tabs) show menu item description as tooltip
- Printing an arbitrary menu just like primary_links and secondary_links


Comments
We’re very excited to get to
We’re very excited to get to the point in the project where we can provide a pre-release version of Windows 8 that is broadly usable by the tech community on a daily basis. We know folks who are anxious to run the Microsoft Windows 8 Consumer Preview are probably interested in suggestions around what hardware to use. This post provides the technical details behind system recommendations.
Post new comment