User login

Adding non-menu things to primary links menu items with Drupal 7's page alter hook

Searched words: 
drupal 7 page alteration altering menu links to add a search form main menu

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.

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

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.