Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

With my module MYMODULE I would like to create external link and place it into main menu. Is it possible to do that in MYMODULE.links.menu.yml file or MYMODULE.routing.yml?

Something like this???

mymodule.links.menu.yml

mymodule.googlecom:
  title: 'Google'
  route_name: 'googlecom'
  menu_name: main

mymodule.routing.yml

googlecom:
  path: 'http://google.com/'
share|improve this question

1 Answer 1

up vote 4 down vote accepted

routing.yml are routes of your site, so they can not be external.

links.menu.yml are links that point to routes, so they can not be external.

To create external links, you need to create them as a menu link content entity in your hook_install() function.

Something like this:

  $menu_link = MenuLinkContent::create(array(
      'title' => 'Link title',
      'path' => 'http://www.google.ch/',
      'menu_name' => 'navigation',
      'weight' => 0,
      'bundle' => 'menu_link_content',
    ));
  $menu_link->save();
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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