Score:0

How to add internal path in *.links.menu.yml

fr flag

I am trying to add an internal link to admin toolbar but I am not able to achieve it.

According to documentation we add an internal link in *.links.menu.yml in the below manner but the link is not being appeared in the toolbar.

hello_world.admin2:
  title: 'Hello module settings'
  description: 'example of how to make an admin settings page link'
  parent: system.admin_config_development
  url: internal:/node/123

I tried the following variants as well but none works. url: 'internal:/node/123' or uri: internal:/node/123 or uri: 'internal:/node/123' .

But the following works url: http://localhost/node/123 .

Can anyone suggest me a way to create a menu link in *.links.menu.yml file.

Use case : I want to provide easily accessible link to user to access one particular page. It is not a route. I am aware of other way to create menu link by using MenuLinkContent::create method. But trying to figure out why above method is not working.

miststudent2011 avatar
fr flag
Related https://drupal.stackexchange.com/questions/253789
Score:2
ru flag

I don't know thy this doesn't work (it is a valid input for Drupal\Core\Url::fromUri), but /node/123 actually has a route:

hello_world.admin2:
  route_name: entity.node.canonical
  route_parameters:
    node: 123

Even though they are valid inputs, it is generally a good idea to avoid internal: URLs if you can use something better. "Something better" is either a route name (in the context of links.yml files) or an entity scheme entity:node/123 (in the context of storing links in the DB). AFAIK internal: was meant for local unrouted URLs like e.g. internal:/robots.txt

miststudent2011 avatar
fr flag
Thank you very much for the hint. It works. Bit i am still wondering why the method in question is not working. I will wait couple of days to check if anyone can provide any additional information on why it is not working. Or else I will mark your answer as accepted answer.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.