Problem/Motivation
In hook_menu_local_tasks_alter() there is an example of adding a local task, depending on the user's access:
function hook_menu_local_tasks_alter(&$data, $route_name, \Drupal\Core\Cache\RefinableCacheableDependencyInterface &$cacheability) {
// Add a tab linking to node/add to all pages.
$data['tabs'][0]['node.add_page'] = [
'#theme' => 'menu_local_task',
'#link' => [
'title' => t('Example tab'),
'url' => Url::fromRoute('node.add_page'),
'localized_options' => [
'attributes' => [
'title' => t('Add content'),
],
],
],
];
// The tab we're adding is dependent on a user's access to add content.
$cacheability->addCacheTags(['user.permissions']);
}
Link to GitLab: https://git.drupalcode.org/project/drupal/-/blob/9.1.x/core/lib/Drupal/C...
It looks like there is a typo because the cache context is added as a cache tag.
Proposed resolution
Replace $cacheability->addCacheTags(['user.permissions']);
with $cacheability->addCacheContexts(['user.permissions']);