I've created a view with a page display, filtering on a specific node type. The view's URL is /admin/poi
.
Now I want to create a local task, linking to this view, for all nodes of type poi
. The local task is showing, but it is visible when viewing/editing any node type, not just my POIs.
wt_poi.routing.yml
wt_poi.admin_list:
path: '/admin/poi'
requirements:
_permission: 'access administration pages'
_custom_access: '\Drupal\wt_poi\Controller\WtPoiController::isAllowedPoiAdminList'
options:
_admin_route: true
wt_poi.links.task.yml
wt_poi.list_overview:
route_name: wt_poi.admin_list
base_route: entity.node.canonical
title: 'List all POIs'
weight: -9999
src/Controller/WtPoiController.php
<?php
namespace Drupal\wt_poi\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Access\AccessResult;
/**
* Controller for the POI node type tasks.
*
*/
class WtPoiController extends ControllerBase {
/**
* Used to limit visibility of local task "List" to POI node type
*/
public function isAllowedPoiAdminList() {
$bundle = false;
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
$bundle = $node->bundle();
}
return AccessResult::forbiddenIf($bundle !== 'poi');
}
}
Why is my _custom_access
check not hiding the local task on other node types?
UPDATE: There seems to be an access check, but it is coming from "Access" in views module "Page settings" and my own access check is completly ignored. Best case would be my access check in addition to the view's access check, in a pinch I would prefer my own custom check replacing the view's access check.