3

How can I pass dynamically route parameters to module.links.action.yml?

My code of module.links.action.yml:

module.group_apply:
  route_name: module.group_apply
  title: 'Subscribe to group'
  weight: 0
  appears_on:
    - entity.node.canonical

My code of module.routing.yml:

module.group_apply:
  path: '/projects/{project}/usergroup/{group}/subscribe'
  defaults:
    _controller: '\Drupal\module\Controller\SubscriptionController::subscribe'
    _title: 'Apply'
  options:
    parameters:
      project:
        type: entity:node
      group:
        type: entity:node
  requirements:
    _permission: 'access content'

My subscibe function (actually):

public function subscribe(NodeInterface $project, NodeInterface $group) {
    return array(
        '#markup' => 'HERE WE GO!',
    );
}
13
  • Can you explain a bit what are you trying to do? Commented Mar 19, 2017 at 0:18
  • /projects/{project}/ /projects/{project}/usergroup/{group}/ this pathes are node-views (contextual filtered by a node-id) And I want to attach some functionality to the views as action links with the contextual attributes like: url.com/projects/32/usergroup/45/subscribe So that I can do some stuff with the information of 32 and 45 (two nodes) Commented Mar 19, 2017 at 8:58
  • This could work, if both routes, the appears_on and the target route have the same two parameters. But this is not what you have in the question.
    – 4uk4
    Commented Mar 19, 2017 at 9:44
  • Excuse me, my comment above is wrong. /project is a view - /project/{project} is a node - /projects/{project}/usergroup/ is a view - /projects/{project}/usergroup/{group} is a node. And i want to insert that action link on the node page of /projects/{project}/usergroup/{group}. Commented Mar 19, 2017 at 11:21
  • 1
    I think you understand it now, alias != route, of course you can replace the missing parameters with fixed ones, but that's not the point
    – 4uk4
    Commented Mar 19, 2017 at 13:02

2 Answers 2

2

1、you can add class to process as follows:

enter image description here

2、you can debug in getRouteParameters function, localAction.php content as follows:

enter image description here

0

I was on the wrong track the whole time.

The right way is to use entity.node.canonical as route (/node/{node}) and using other variables from node itself in the subscribe function ($node).

Thank you @4k4 for your help.

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.