I have 2 node content types / bundles, A and B. each A has a relationship with multiple Bs. When on the edit page, node/%/edit, for A, I want to show a link to the list of related B so that an editor can easily see a prefiltered list of B for A.
I have created a route:
in my_module.routing.yml
my_module.related_B:
path: '/node/{node}/related_b'
base_route: entity.node.canonical
options:
_admin_route: TRUE
and have configured a view page at the same url node/%/related_b
that contextually filters porperly. no issues there.
The link is added to the menu via the my_module.links.task.yml
my_module.related_B:
route_name: my_module.related_B
title: 'Related B'
base_route: entity.node.canonical
weight: 100
Everything shows up and looks/works the way I want it to.
The problem is that I cannot seem to figure out how to limit that link/view to only show and work when on the edit page for an instance of content A. It shows on EVERY node edit page.
I've tried the following and did not seem to get anywhere:
- trying to hook into
hook_local_tasks_alter
inmy_module.module
- custom
RouteSubscriber
Plugin
In D7 I was abel to accomplish this with a hook and access callback:
function my_module_menu()
{
$items = array();
// Single sync functionality
$items['node/%node/related_B'] = array(
'title' => 'Related B',
'page callback' => '_B_page_callback',
'page arguments' => array(1),
'access callback' => '_B_access_callback',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function _A_access_callback($node)
{
if($node->type == 'A' && user_access('administer nodes'))
{
return TRUE;
}
return FALSE;
}