From 221ec16f7c80acb8d71de9cb2bfae325bbea7150 Mon Sep 17 00:00:00 2001 From: Lauri Eskola <lauri.eskola@acquia.com> Date: Wed, 4 Dec 2019 17:25:43 +0200 Subject: [PATCH] Issue #3005403 by alexpott, Lennard Westerveld, rensingh99, lauriii, xjm: Cannot delete or edit a block that is placed in a section of the layout_builder --- .../Theme/ClaroLayoutBuilderTest.php | 111 +++++++++++++++++ .../Theme/SevenLayoutBuilderTest.php | 112 ++++++++++++++++++ core/themes/claro/claro.theme | 4 +- core/themes/seven/seven.theme | 4 +- 4 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 core/tests/Drupal/FunctionalTests/Theme/ClaroLayoutBuilderTest.php create mode 100644 core/tests/Drupal/FunctionalTests/Theme/SevenLayoutBuilderTest.php diff --git a/core/tests/Drupal/FunctionalTests/Theme/ClaroLayoutBuilderTest.php b/core/tests/Drupal/FunctionalTests/Theme/ClaroLayoutBuilderTest.php new file mode 100644 index 000000000000..a198c110ea49 --- /dev/null +++ b/core/tests/Drupal/FunctionalTests/Theme/ClaroLayoutBuilderTest.php @@ -0,0 +1,111 @@ +<?php + +namespace Drupal\FunctionalTests\Theme; + +use Drupal\Tests\BrowserTestBase; + +/** + * Tests the layout builder with the Claro theme. + * + * @group claro + */ +class ClaroLayoutBuilderTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'claro'; + + /** + * {@inheritdoc} + */ + public static $modules = [ + 'views', + 'layout_builder', + 'layout_builder_views_test', + 'layout_test', + 'block', + 'block_test', + 'node', + 'layout_builder_test', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->drupalPlaceBlock('local_tasks_block', ['region' => 'header']); + + // Create two nodes. + $this->createContentType([ + 'type' => 'bundle_with_section_field', + 'name' => 'Bundle with section field', + ]); + $this->createNode([ + 'type' => 'bundle_with_section_field', + 'title' => 'The first node title', + 'body' => [ + [ + 'value' => 'The first node body', + ], + ], + ]); + $this->createNode([ + 'type' => 'bundle_with_section_field', + 'title' => 'The second node title', + 'body' => [ + [ + 'value' => 'The second node body', + ], + ], + ]); + } + + /** + * Tests the layout builder has expected contextual links with Claro. + * + * @see claro.theme + */ + public function testContextualLinks() { + $assert_session = $this->assertSession(); + $page = $this->getSession()->getPage(); + + $this->drupalLogin($this->drupalCreateUser([ + 'configure any layout', + 'administer node display', + 'administer node fields', + 'access contextual links', + ])); + + $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field'; + + // From the manage display page, go to manage the layout. + $this->drupalGet("$field_ui_prefix/display/default"); + $assert_session->linkNotExists('Manage layout'); + $assert_session->fieldDisabled('layout[allow_custom]'); + + $this->drupalPostForm(NULL, ['layout[enabled]' => TRUE], 'Save'); + $assert_session->linkExists('Manage layout'); + $this->clickLink('Manage layout'); + + // Add a new block. + $assert_session->linkExists('Add block'); + $this->clickLink('Add block'); + $assert_session->linkExists('Powered by Drupal'); + $this->clickLink('Powered by Drupal'); + $page->fillField('settings[label]', 'This is the label'); + $page->checkField('settings[label_display]'); + $page->pressButton('Add block'); + + // Test that the block has the contextual class applied and the container + // for contextual links. + $assert_session->elementExists('css', 'div.block-system-powered-by-block.contextual-region div[data-contextual-id]'); + + // Ensure other blocks do not have contextual links. + $assert_session->elementExists('css', 'div.block-page-title-block'); + $assert_session->elementNotExists('css', 'div.block-page-title-block.contextual-region div[data-contextual-id]'); + } + +} diff --git a/core/tests/Drupal/FunctionalTests/Theme/SevenLayoutBuilderTest.php b/core/tests/Drupal/FunctionalTests/Theme/SevenLayoutBuilderTest.php new file mode 100644 index 000000000000..ff668895813d --- /dev/null +++ b/core/tests/Drupal/FunctionalTests/Theme/SevenLayoutBuilderTest.php @@ -0,0 +1,112 @@ +<?php + +namespace Drupal\FunctionalTests\Theme; + +use Drupal\Tests\BrowserTestBase; + +/** + * Tests the Seven theme. + * + * @group seven + */ +class SevenLayoutBuilderTest extends BrowserTestBase { + + /** + * {@inheritdoc} + */ + protected $defaultTheme = 'seven'; + + /** + * {@inheritdoc} + */ + public static $modules = [ + 'views', + 'layout_builder', + 'layout_builder_views_test', + 'layout_test', + 'block', + 'block_test', + 'node', + 'layout_builder_test', + ]; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->drupalPlaceBlock('page_title_block', ['region' => 'header']); + $this->drupalPlaceBlock('local_tasks_block', ['region' => 'header']); + + // Create two nodes. + $this->createContentType([ + 'type' => 'bundle_with_section_field', + 'name' => 'Bundle with section field', + ]); + $this->createNode([ + 'type' => 'bundle_with_section_field', + 'title' => 'The first node title', + 'body' => [ + [ + 'value' => 'The first node body', + ], + ], + ]); + $this->createNode([ + 'type' => 'bundle_with_section_field', + 'title' => 'The second node title', + 'body' => [ + [ + 'value' => 'The second node body', + ], + ], + ]); + } + + /** + * Tests the layout builder has expected contextual links with Seven. + * + * @see seven.theme + */ + public function testContextualLinks() { + $assert_session = $this->assertSession(); + $page = $this->getSession()->getPage(); + + $this->drupalLogin($this->drupalCreateUser([ + 'configure any layout', + 'administer node display', + 'administer node fields', + 'access contextual links', + ])); + + $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field'; + + // From the manage display page, go to manage the layout. + $this->drupalGet("$field_ui_prefix/display/default"); + $assert_session->linkNotExists('Manage layout'); + $assert_session->fieldDisabled('layout[allow_custom]'); + + $this->drupalPostForm(NULL, ['layout[enabled]' => TRUE], 'Save'); + $assert_session->linkExists('Manage layout'); + $this->clickLink('Manage layout'); + + // Add a new block. + $assert_session->linkExists('Add block'); + $this->clickLink('Add block'); + $assert_session->linkExists('Powered by Drupal'); + $this->clickLink('Powered by Drupal'); + $page->fillField('settings[label]', 'This is the label'); + $page->checkField('settings[label_display]'); + $page->pressButton('Add block'); + + // Test that the block has the contextual class applied and the container + // for contextual links. + $assert_session->elementExists('css', 'div.block-system-powered-by-block.contextual-region div[data-contextual-id]'); + + // Ensure other blocks do not have contextual links. + $assert_session->elementExists('css', 'div.block-page-title-block'); + $assert_session->elementNotExists('css', 'div.block-page-title-block.contextual-region div[data-contextual-id]'); + } + +} diff --git a/core/themes/claro/claro.theme b/core/themes/claro/claro.theme index bc6bcfed7b0f..df810f09b8fb 100644 --- a/core/themes/claro/claro.theme +++ b/core/themes/claro/claro.theme @@ -175,10 +175,10 @@ function claro_preprocess_entity_add_list(&$variables) { /** * Implements hook_preprocess_block() for block content. * - * Disables contextual links for all blocks. + * Disables contextual links for all blocks except for layout builder blocks. */ function claro_preprocess_block(&$variables) { - if (isset($variables['title_suffix']['contextual_links'])) { + if (isset($variables['title_suffix']['contextual_links']) && !isset($variables['elements']['#contextual_links']['layout_builder_block'])) { unset($variables['title_suffix']['contextual_links']); unset($variables['elements']['#contextual_links']); diff --git a/core/themes/seven/seven.theme b/core/themes/seven/seven.theme index 740f1bd28d6f..08a594b5a533 100644 --- a/core/themes/seven/seven.theme +++ b/core/themes/seven/seven.theme @@ -89,10 +89,10 @@ function seven_preprocess_block_content_add_list(&$variables) { /** * Implements hook_preprocess_block() for block content. * - * Disables contextual links for all blocks. + * Disables contextual links for all blocks except for layout builder blocks. */ function seven_preprocess_block(&$variables) { - if (isset($variables['title_suffix']['contextual_links'])) { + if (isset($variables['title_suffix']['contextual_links']) && !isset($variables['elements']['#contextual_links']['layout_builder_block'])) { unset($variables['title_suffix']['contextual_links']); unset($variables['elements']['#contextual_links']); -- GitLab