I have a local links.task.yml file to display the tab for the node data , But it seems to have a problem passing argument to the path . As you can see i am extending the node's basic fetaures like edit,delete.revision with an additional function using tab . I have module_name.links.task.yml

  route_name: module_name.my_route
  base_route: entity.node.canonical
  title: My title

And i have the route in module_name.routing.yml as follows

  path: '/node/{arg1}/function_name'
    _controller: '\Drupal\module_name\Controller\ControllerName::function_name'
    _title: 'My title'
    _permission: 'access admin tab'

But it throws me error like :

Symfony\Component\Routing\Exception\MissingMandatoryParametersException: Some mandatory parameters are missing ("arg1") to generate a URL for route "module_name.my_route".

How can i pass variables in links.task.yml file ?

  • 1
    I already attempted to answered this to you in Convert hook_menu in drupal 8. Also have a look at the linked resource (halfway in the asnwer): Parameters in Routes and the sub-pages. – Neograph734 May 12 '16 at 15:14
  • I think you mistaken the question , its to use parameters in links.yml not in routing.yml – Crazyrubixfan May 12 '16 at 15:27
  • Links are only references to routes. The error comes from your routing. – Neograph734 May 12 '16 at 15:34
  • 1
    I guess, because you are working with nodes, your variable should be called {node} so the existing node routing can work with it. Can you try that in your routing file? – Neograph734 May 12 '16 at 15:41

The problem is that you are using {arg1} in your route and your links.task.yml file is registering that as an item that should use base route entity.node.canonical. As you can read in this change record, the value for entity.node.canonical will become node/[nid].

In your situation, you are providing a variable arg1, when the node routing system is expecting a node variable.

Just make sure that all sub-pages share the same base path as their parents.


In your module_name.links.task.yml file you can add a route_parameters: array that lists the parameters you want to pass, in your case it would end up:

  route_name: module_name.my_route
  base_route: entity.node.canonical
  title: My title
    arg1:  'value_for_arg1'

You can find this by looking at the code in \Drupal\Core\Menu\LocalTaskManager which parses this file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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