2

I have the following,

In the routing.yml

mymodule.cache_clear:
  path: '/node/{node}/cache'
  defaults:
    _form:  '\Drupal\mymodule\Form\APICacheClearForm'
    _title: 'Cache Clear'
  requirements:
    _permission: 'access content'
    entity: \d+
  options:
    _admin_route: TRUE
    parameters:
      node_type:
        type: entity:node
        bundle:
          - blog

In the links.task.yml

mymodule.cache_clear:
  title: 'Cache Clear'
  route_name: topgun_api.cache_clear
  route_parameters: { node_type: blog }
  base_route: entity.node.canonical

I don't see the tab being shown only on blog content type.

Is it not possible to accomplish this without using _custom_access?

2 Answers 2

1

The code below work for me.

in the routing.yml

mymodule.cache_clear:
  path: '/node/{node}/cache'
  defaults:
    _form:  '\Drupal\mymodule\Form\APICacheClearForm'
    _title: 'Cache Clear'
  requirements:
    _permission: 'access content'
    node: \d+
  options:
    _admin_route: TRUE
    parameters:
      node:
        type: entity:node
        bundle:
          - blog

In the links.task.yml

mymodule.cache_clear:
  title: 'Cache Clear'
  route_name: mymodule.cache_clear
  route_parameters: { node_type: blog }
  base_route: entity.node.canonical
0

Is it not possible to accomplish this without using _custom_access?

The other alternative is:

mymodule.links.task.yml

mymodule.cache_clear:
  title: 'Cache Clear'
  route_name: mymodule.cache_clear
  base_route: entity.node.canonical

mymodule.module

/**
* Implements hook_menu_local_actions_alter().
*/
function mymodule_menu_local_tasks_alter(&$data, $route_name) {
  // Load the node entity based on the current route parameters.
  $route_match = \Drupal::routeMatch();
  $node = $route_match->getParameter('node');

  // Remove if it's not a blog type.
  if ($node instanceof \Drupal\node\NodeInterface
    && $node->getType() != 'blog') {
     unset($data['tabs'][0]['mymodule.cache_clear']);
  }
}

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.