Defining module.links.action.yml with route parameters

by Drupalorocks   Last Updated March 18, 2017 23:07 PM

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!',
    );
}


Answers 1


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.

LordOfThePings
LordOfThePings
March 25, 2017 10:36 AM

Related Questions



Problem with menu position module

Updated December 10, 2016 08:03 AM

How to add module to admin/config page?

Updated August 02, 2017 13:07 PM