diff --git a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php index 14fa80ed50..c53c5a76bf 100644 --- a/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php +++ b/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php @@ -400,7 +400,7 @@ public function setComponent($name, array $options = []) { // @todo Remove workaround for EntityViewBuilder::getSingleFieldDisplay() in // https://www.drupal.org/project/drupal/issues/2936464. - if ($this->isNew()) { + if ($this->getMode() === static::CUSTOM_MODE) { return $this; } diff --git a/core/modules/layout_builder/src/Form/RevertOverridesForm.php b/core/modules/layout_builder/src/Form/RevertOverridesForm.php index 54d33634fd..b6d07d9089 100644 --- a/core/modules/layout_builder/src/Form/RevertOverridesForm.php +++ b/core/modules/layout_builder/src/Form/RevertOverridesForm.php @@ -73,6 +73,13 @@ public function getQuestion() { return $this->t('Are you sure you want to revert this to defaults?'); } + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return $this->t('Revert'); + } + /** * {@inheritdoc} */ diff --git a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php index 0a49465e4b..fb8bcb2110 100644 --- a/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php +++ b/core/modules/layout_builder/src/Plugin/Block/FieldBlock.php @@ -147,8 +147,8 @@ public function build() { protected function blockAccess(AccountInterface $account) { $entity = $this->getEntity(); - // First consult the entity. - $access = $entity->access('view', $account, TRUE); + // First consult the entity, except not while the entity is being previewed. + $access = empty($entity->in_preview) ? $entity->access('view', $account, TRUE) : AccessResult::allowed(); if (!$access->isAllowed()) { return $access; } diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php new file mode 100644 index 0000000000..fd6a6afaf2 --- /dev/null +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -0,0 +1,180 @@ +drupalPlaceBlock('local_tasks_block'); + + // Create two nodes. + $this->createContentType(['type' => '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', + ], + ], + ]); + + $this->drupalLogin($this->drupalCreateUser([ + 'configure any layout', + 'administer node display', + 'administer node fields', + ])); + } + + /** + * {@inheritdoc} + */ + public function testLayoutBuilderUi() { + $assert_session = $this->assertSession(); + $page = $this->getSession()->getPage(); + + $this->drupalGet('node/1'); + $assert_session->pageTextContains('The first node body'); + $assert_session->pageTextNotContains('Powered by Drupal'); + $assert_session->linkNotExists('Layout'); + + $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->linkExists('Manage layout'); + $this->clickLink('Manage layout'); + $assert_session->addressEquals("$field_ui_prefix/display-layout/default"); + // The body field is present. + $assert_session->elementExists('css', '.field--name-body'); + + // 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'); + $assert_session->pageTextContains('Powered by Drupal'); + $assert_session->pageTextContains('This is the label'); + $assert_session->addressEquals("$field_ui_prefix/display-layout/default"); + + // Save the defaults. + $assert_session->linkExists('Save Layout'); + $this->clickLink('Save Layout'); + $assert_session->addressEquals("$field_ui_prefix/display/default"); + + // The node uses the defaults, no overrides available. + $this->drupalGet('node/1'); + $assert_session->pageTextContains('The first node body'); + $assert_session->pageTextContains('Powered by Drupal'); + $assert_session->linkNotExists('Layout'); + + // Enable overrides. + $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[allow_custom]' => TRUE], 'Save'); + $this->drupalGet('node/1'); + + // Remove the section from the defaults. + $assert_session->linkExists('Layout'); + $this->clickLink('Layout'); + $assert_session->linkExists('Remove section'); + $this->clickLink('Remove section'); + $page->pressButton('Remove'); + + // Add a new section. + $this->clickLink('Add Section'); + $assert_session->linkExists('Two column'); + $this->clickLink('Two column'); + $assert_session->linkExists('Save Layout'); + $this->clickLink('Save Layout'); + $assert_session->pageTextNotContains('The first node body'); + $assert_session->pageTextNotContains('Powered by Drupal'); + + // Alter the defaults. + $this->drupalGet("$field_ui_prefix/display-layout/default"); + $assert_session->linkExists('Add Block'); + $this->clickLink('Add Block'); + $assert_session->linkExists('Title'); + $this->clickLink('Title'); + $page->pressButton('Add Block'); + // The title field is present. + $assert_session->elementExists('css', '.field--name-title'); + $this->clickLink('Save Layout'); + + // View the other node, which is still using the defaults. + $this->drupalGet('node/2'); + $assert_session->pageTextContains('The second node title'); + $assert_session->pageTextContains('The second node body'); + $assert_session->pageTextContains('Powered by Drupal'); + + // The overridden node does not pick up the changes to defaults. + $this->drupalGet('node/1'); + $assert_session->elementNotExists('css', '.field--name-title'); + $assert_session->pageTextNotContains('The first node body'); + $assert_session->pageTextNotContains('Powered by Drupal'); + $assert_session->linkExists('Layout'); + + // Reverting the override returns it to the defaults. + $this->clickLink('Layout'); + $assert_session->linkExists('Revert to defaults'); + $this->clickLink('Revert to defaults'); + $page->pressButton('Revert'); + $assert_session->pageTextContains('The layout has been reverted back to defaults.'); + $assert_session->elementExists('css', '.field--name-title'); + $assert_session->pageTextContains('The first node body'); + $assert_session->pageTextContains('Powered by Drupal'); + + // Add a new field. + $edit = [ + 'new_storage_type' => 'string', + 'label' => 'My text field', + 'field_name' => 'my_text', + ]; + $this->drupalPostForm("$field_ui_prefix/fields/add-field", $edit, 'Save and continue'); + $page->pressButton('Save field settings'); + $page->pressButton('Save settings'); + $this->drupalGet("$field_ui_prefix/display-layout/default"); + $assert_session->pageTextContains('My text field'); + $assert_session->elementExists('css', '.field--name-field-my-text'); + + // Delete the field. + $this->drupalPostForm("$field_ui_prefix/fields/node.bundle_with_section_field.field_my_text/delete", [], 'Delete'); + $this->drupalGet("$field_ui_prefix/display-layout/default"); + $assert_session->pageTextNotContains('My text field'); + $assert_session->elementNotExists('css', '.field--name-field-my-text'); + } + +}