diff --git a/core/modules/block/src/Tests/BlockAdminThemeTest.php b/core/modules/block/src/Tests/BlockAdminThemeTest.php index e2f44a3392d18cff9e77570e78f7461590dd7db0..7d34c3b14e65dace173447b243214064fa18abb9 100644 --- a/core/modules/block/src/Tests/BlockAdminThemeTest.php +++ b/core/modules/block/src/Tests/BlockAdminThemeTest.php @@ -21,7 +21,7 @@ class BlockAdminThemeTest extends WebTestBase { * * @var array */ - public static $modules = array('block'); + public static $modules = array('block', 'contextual'); /** * Check for the accessibility of the admin theme on the block admin page. @@ -43,4 +43,40 @@ function testAdminTheme() { $this->drupalGet('admin/structure/block/list/bartik'); $this->assertResponse(200); } + + /** + * Ensure contextual links are disabled in Seven theme. + */ + function testSevenAdminTheme() { + // Create administrative user. + $admin_user = $this->drupalCreateUser([ + 'access administration pages', + 'administer themes', + 'access contextual links', + 'view the administration theme', + ]); + $this->drupalLogin($admin_user); + + // Install admin theme and confirm that tab is accessible. + \Drupal::service('theme_handler')->install(['seven']); + $edit['admin_theme'] = 'seven'; + $this->drupalPostForm('admin/appearance', $edit, t('Save configuration')); + + // Define our block settings. + $settings = [ + 'theme' => 'seven', + 'region' => 'header', + ]; + + // Place a block. + $block = $this->drupalPlaceBlock('local_tasks_block', $settings); + + // Open admin page. + $this->drupalGet('admin'); + + // Check if contextual link classes are unavailable. + $this->assertNoRaw('
'); + $this->assertNoRaw('contextual-region'); + } + } diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme index 7bd56e04443fcc8f764db6f121faf30b5ad70f02..4f7946cb5e40a23abeb4854ebd45d2b07cccee4d 100644 --- a/core/themes/seven/seven.theme +++ b/core/themes/seven/seven.theme @@ -83,6 +83,20 @@ function seven_preprocess_block_content_add_list(&$variables) { } } +/** + * Implements hook_preprocess_block() for block content. + * + * Disables contextual links for all blocks. + */ +function seven_preprocess_block(&$variables) { + if (isset($variables['title_suffix']['contextual_links'])) { + unset($variables['title_suffix']['contextual_links']); + unset($variables['elements']['#contextual_links']); + + $variables['attributes']['class'] = array_diff($variables['attributes']['class'], ['contextual-region']); + } +} + /** * Implements hook_preprocess_HOOK() for block admin page templates. */