From a49ba3385355f768a258c815cd4af891dba6c241 Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Fri, 20 Dec 2024 09:30:24 +1000 Subject: [PATCH] Issue #3444745 by fjgarlin, plopesc, m4olivei: Navigation Top Bar hides entity local tasks even if the user has no access to the bar --- core/modules/navigation/navigation.module | 4 +++- .../tests/src/Functional/NavigationTopBarTest.php | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/modules/navigation/navigation.module b/core/modules/navigation/navigation.module index 578b73205e9..63d000f645c 100644 --- a/core/modules/navigation/navigation.module +++ b/core/modules/navigation/navigation.module @@ -158,7 +158,9 @@ function navigation_menu_links_discovered_alter(&$links) { function navigation_block_build_local_tasks_block_alter(array &$build, BlockPluginInterface $block) { $navigation_renderer = \Drupal::service('navigation.renderer'); assert($navigation_renderer instanceof NavigationRenderer); - $navigation_renderer->removeLocalTasks($build, $block); + if (\Drupal::currentUser()->hasPermission('access navigation')) { + $navigation_renderer->removeLocalTasks($build, $block); + } } /** diff --git a/core/modules/navigation/tests/src/Functional/NavigationTopBarTest.php b/core/modules/navigation/tests/src/Functional/NavigationTopBarTest.php index 84fc5a0acdc..e6ea0e99af0 100644 --- a/core/modules/navigation/tests/src/Functional/NavigationTopBarTest.php +++ b/core/modules/navigation/tests/src/Functional/NavigationTopBarTest.php @@ -99,6 +99,15 @@ class NavigationTopBarTest extends BrowserTestBase { $this->assertSession()->elementTextEquals('xpath', "//div[contains(@class, 'top-bar__content')]/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"]'); } }