Someone can help me ? I want to display a tab only when the content type is 'test'.
Here's my files.
mymodule.routing.yml :
mymodule.check_test:
path: '/checktest/{node}'
defaults:
_controller: '\Drupal\mymodule\Controller\CheckTestController::content'
requirements:
_access: 'TRUE'
mymodule.links.task.yml :
mymodule.check_test:
title: Display tests
route_name: mymodule.check_test
base_route: entity.node.canonical
My tab is displayed for every content, i don't know how to filter with my content type...
Thanks :).
Edit : From mradcliffe's answer,
I've add a mymodule.services.yml :
services:
access_check.test:
class: Drupal\mymodule\Access\MyModuleTestAccess
tags:
- { name: access_check, applies_to: _access_test }
and a MyModuleTestAccess class with :
public function access(NodeInterface $node)
{
return AccessResult::allowedIf($node->bundle() === 'test');
}
My edited mymodule.routing.yml :
mymodule.check_test:
path: '/checktest/{node}'
defaults:
_controller: '\Drupal\mymodule\Controller\CheckTestController::content'
requirements:
_access_test: ''
_access_test: ' '
must now be_access_test: 'true'
.