Skip to content
Snippets Groups Projects
Verified Commit 9177c489 authored by Lee Rowlands's avatar Lee Rowlands
Browse files

Issue #3444745 by fjgarlin, plopesc, m4olivei: Navigation Top Bar hides entity...

Issue #3444745 by fjgarlin, plopesc, m4olivei: Navigation Top Bar hides entity local tasks even if the user has no access to the bar
parent 662da7ee
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@
use Drupal\navigation\NavigationRenderer;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\navigation\TopBarItemManagerInterface;
/**
* Hook implementations for navigation.
......@@ -120,7 +121,11 @@ public function menuLinksDiscoveredAlter(&$links): void {
public function blockBuildLocalTasksBlockAlter(array &$build, BlockPluginInterface $block): void {
$navigation_renderer = \Drupal::service('navigation.renderer');
assert($navigation_renderer instanceof NavigationRenderer);
$navigation_renderer->removeLocalTasks($build, $block);
if (\Drupal::currentUser()->hasPermission('access navigation') &&
array_key_exists('page_actions', \Drupal::service(TopBarItemManagerInterface::class)->getDefinitions())
) {
$navigation_renderer->removeLocalTasks($build, $block);
}
}
/**
......
......@@ -114,6 +114,15 @@ public function testTopBarVisibility(): void {
$this->assertSession()->elementTextEquals('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/button/span", 'More actions');
$this->assertSession()->elementNotExists('xpath', '//div[@id="block-tabs"]');
}
// Regular tabs are visible for user that cannot access to navigation.
$this->drupalLogin($this->drupalCreateUser([
'bypass node access',
]));
$this->drupalGet($this->node->toUrl());
$this->assertSession()->elementNotExists('xpath', "//div[contains(@class, 'top-bar__content')]/div[contains(@class, 'top-bar__actions')]/button/span");
$this->assertSession()->elementExists('xpath', '//div[@id="block-tabs"]');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment