Skip to main content


Forcing all menu links to use absolute links in Drupal 8

In a recent project, we were using an external service that pulls our site into their system and injects their content into our project. The issue we ran into was that the third party was overwriting all links in the template we provided with their HTTP host, causing the menu system from our Drupal site to break. To get around this we needed to generate absolute links for all of our menus.

In order to accomplish this we used template_preprocess() to dynamically provide our site's hostname as a variable:

Programmatically alter a Drupal menu without disabling access to the page.

I came across a need to keep a menu link active, but, I didn't want it to be displayed to the anonymous user. After much searching I found the hook_menu_link_alter() function and the hook_translated_menu_link_alter() function.

With these functions, I was able to alter the menu item that I wanted to not display with hook_menu_link_alter():

Views menu tab displayed on only certain content types.

I recently ran into an issue where I wanted to use a views page as a tab for nodes of type 'course'. I added the view page like normal, providing my path of: node/%/course-list.

Next, I added my menu item entry as a 'menu tab'.

Perfect, except that the menu tab was displaying on every node when I needed it to only display on one node type.

Secondary links displaying on the home page

In a recent project I needed to have my secondary links display on the home page, but for some reason they weren't displaying. I had the source for the secondary menu set in the menu settings to be the 'main menu' and my 'main menu' was setup like this:

  • Home
    • Sub 1
    • Sub 2
  • Nav 1
  • etc.

My 'Home' link's href was set to <front> and the secondary links worked perfectly, except on the home page.