Dynamic local tasks to the same route with slug

by Gábor   Last Updated October 09, 2019 07:07 AM - source

I have a route set up with a slug accepting taxonomy terms (routing.yml):

  path: '/column/{taxonomy_term}'

I would like to add (secondary, although that's not important) local task tabs on a page, one for each possible term of the vocabulary used (links.task.yml):

  deriver: 'Drupal\example\Plugin\Derivative\ColumnTasks'
  parent_id: example.parent

The deriver is pretty straightforward and simple and mentioned in a few docs on drupal.org, the relevant part is:

foreach ($columns as $column) {
  $route_name = 'example.column';
  $this->derivatives[$route_name] = [
    'title' => $column->getName(),
    'route_name' => $route_name,
    'route_parameters' => ['taxonomy_term' => $column->id()],
    'parent_id' => 'example.parent',
  ] + $base_plugin_definition;

The problem is that this code, obviously, doesn't generate more than one tab because all go to the same $route_name. But I'm not allowed to use any other route name (suffixing it with the term, for instance) because it complains about a non-existent route then.

Do I have any other solution than to generate all the routes separately, using a _route_callback? This would somehow feel wrong, going against the reason for the existence of slugs in the first place.

Tags : 8 routes

Answers 1

The array key is not the route name, it's the machine name of the local task. It's pretty common to use the same string but that's in no way a requirement.

Just use a different array key and this should work.

May 30, 2018 13:40 PM

Related Questions

How do you set a one-off access checker on a route?

Updated December 01, 2016 08:03 AM

add class to LI

Updated December 25, 2016 08:03 AM

Routing match everything

Updated January 10, 2017 08:03 AM