I have one menu link available in the Main Menu. It is called as "Video".

In my system, there is vocabulary called as "Video Taxonomies". It have following taxonomies entries.

  1. Entertainment
  2. Comedy
  3. Friction

I have created one block for listing all this category.

Now, I want this block result would appear under "Video" link of the Main Menu.

So, I want following output when we will hover on the Video Link of the Main menu.

  • Video Link

    • Entertainment
    • Comedy
    • Friction

I have used https://www.drupal.org/project/menu_views for Drupal 7.

Please suggest.

  • Menu links are managed with a plugin manager. You can achieve this task by implementing a plugin deriver class for the menu links plugin.
    – Eyal
    Dec 29, 2016 at 8:41
  • Thanks for your answer. Plearse do check the following code. We have used that for creating the sub menu and please let me know if there is proper way. Dec 30, 2016 at 8:22

1 Answer 1


We have implemented using the


In which, We have accessed the result of the block by using the following code.

 $result = views_get_view_result("view_name", "display_id");
    foreach($result as $result) {
      $title = "Entertainment"; // we have took as static
      $tid = 10;
      $slug = str_replace(' ', '_', strtolower($title));
      $links[$slug] = array(
        'title' => $title,
        'route_name' => 'view.VIEW_NAME.DISPLAY_ID'
        'route_parameters' => array('arg_0' => $tid),
        'description' => 'Dynamic',
        'provider' => 'MODULE_NAME',
        'parent' => 'menu_link_content:DATABASE_UUID_OF_SELECTED_CATEGORY',
        'id' => $slug

We have used route_name for assigning the url, this url should be the existing url of the drupal site.

We need route_parameters for passing the arguments.

For accessing the Video Link : reference in parent of $links. I have got it from the

SELECT uuid as DATABASE_UUID_OF_SELECTED_CATEGORY FROM `menu_link_content` where id = "TID_Video_Link_of_Main_menu"

After that, We have used that id in parent as 'menu_link_content:04c479c9-7234-4de2-a4f0-e03b0a3003b6' so all links will be added below the Video Link of the main menu.

After doing all the code and we need to clear the cache. And we are able to see the sub menu from the views of texonomy to Video Link of the main menu.

Please suggest me if there is any better way than this.

For Reference: https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Menu!menu.api.php/function/hook_menu_links_discovered_alter/8.2.x

  • Your code would be a lot more maintainable if you used a deriver class instead. But don't worry, it takes some time to get use to writing for drupal 8.
    – Eyal
    Dec 30, 2016 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.