0

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

example.column:
  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):

example.column_list:
  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.

0

1 Answer 1

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.

1
  • Indeed. I could've sworn I tried that as well but apparently not. Thanks.
    – Gábor
    May 30, 2018 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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