diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php b/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php index 43a9c604b0..fba52121bf 100644 --- a/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php +++ b/core/modules/layout_builder/src/Plugin/SectionStorage/DefaultsSectionStorage.php @@ -169,6 +169,7 @@ public function buildRoutes(RouteCollection $collection) { $options = $entity_route->getOptions(); $options['_admin_route'] = FALSE; + $options['no_cache'] = TRUE; $this->buildLayoutRoutes($collection, $this->getPluginDefinition(), $path, $defaults, $requirements, $options, $entity_type_id, 'entity_view_display'); diff --git a/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php b/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php index ec2dc5babd..937b382db7 100644 --- a/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php +++ b/core/modules/layout_builder/src/Plugin/SectionStorage/OverridesSectionStorage.php @@ -148,23 +148,6 @@ public function getStorageId() { return $entity->getEntityTypeId() . '.' . $entity->id(); } - /** - * Returns the ID of the layout entity form for this plugin. - * - * @return string - * The form ID for this layout's entity form. - */ - public function getEntityFormId() { - $entity = $this->getEntity(); - $type = $entity->getEntityTypeId(); - $bundle = $entity->bundle(); - $id_parts = [$bundle, 'layout-builder-form']; - if ($type !== $bundle) { - array_unshift($id_parts, $type); - } - return implode('-', $id_parts); - } - /** * {@inheritdoc} */ @@ -281,6 +264,8 @@ public function buildRoutes(RouteCollection $collection) { $requirements = $collection->get("entity.$entity_type_id.canonical")->getRequirements(); $options = []; + $options['no_cache'] = TRUE; + // Ensure that upcasting is run in the correct order. $options['parameters']['section_storage'] = []; $options['parameters'][$entity_type_id]['type'] = 'entity:' . $entity_type_id; diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php index df922c2cae..2377b2ef20 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -781,10 +781,14 @@ public function testConcurrentEditing() { 'administer node display', ]); + $display_path = 'admin/structure/types/manage/bundle_with_section_field/display/default'; + $this->drupalLogin($user1); - $this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', ['layout[enabled]' => TRUE], 'Save'); + $this->drupalPostForm($display_path, ['layout[enabled]' => TRUE], 'Save'); + $this->drupalPostForm($display_path, ['layout[allow_custom]' => TRUE], 'Save'); - $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout'); + // Test concurrent editing with defaults. + $this->drupalGet("$display_path/layout"); $assert_session->elementsCount('css', '.layout-builder__section', 1); $assert_session->elementNotExists('css', '.layout--twocol-section'); $page->clickLink('Add section'); @@ -800,7 +804,7 @@ public function testConcurrentEditing() { $this->drupalLogout(); $this->drupalLogin($user2); - $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout'); + $this->drupalGet("$display_path/layout"); $assert_session->elementsCount('css', '.layout-builder__section', 0); $assert_session->pageTextContains(sprintf('This layout is being edited by user %s, and is therefore locked from editing by others.', $user1->getDisplayName())); $assert_session->pageTextNotContains('You have unsaved changes.'); @@ -813,7 +817,7 @@ public function testConcurrentEditing() { $layout_tempstore_before = $this->container->get('tempstore.shared')->get('layout_builder.section_storage.defaults')->getMetadata('node.bundle_with_section_field.default'); $this->assertNotNull($layout_tempstore_before); - $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout'); + $this->drupalGet("$display_path/layout"); $page->clickLink('break this lock'); $page->pressButton('Confirm'); @@ -824,7 +828,59 @@ public function testConcurrentEditing() { $assert_session->pageTextNotContains(sprintf('This layout is being edited by user %s, and is therefore locked from editing by others.', $user1->getDisplayName())); $assert_session->elementsCount('css', '.layout-builder__section', 1); $assert_session->elementNotExists('css', '.layout--twocol-section'); + $assert_session->pageTextNotContains('You have unsaved changes.'); + $assert_session->pageTextContains('The changes to the layout have been discarded.'); + $assert_session->buttonExists('Save layout'); + $assert_session->buttonExists('Discard changes'); + + // Test concurrent editing with overrides. + $this->drupalGet('node/1/layout'); + $assert_session->elementsCount('css', '.layout-builder__section', 1); + $assert_session->elementNotExists('css', '.layout--twocol-section'); + $page->clickLink('Add section'); + $page->clickLink('Two column'); + $page->pressButton('Add section'); + $assert_session->elementsCount('css', '.layout-builder__section', 2); + $assert_session->pageTextContains('You have unsaved changes.'); + $assert_session->buttonExists('Discard changes'); + $page->pressButton('Save layout'); + $this->drupalGet('node/1/layout'); + $page->clickLink('Add section'); + $page->clickLink('Three column'); + $page->pressButton('Add section'); + $assert_session->elementsCount('css', '.layout-builder__section', 3); + $assert_session->elementExists('css', '.layout--threecol-section'); + $assert_session->pageTextContains('You have unsaved changes.'); + + $this->drupalGet('layout_builder/configure/section/overrides/node.1/0'); + $assert_session->statusCodeEquals(200); + $this->drupalLogout(); + + $this->drupalLogin($user1); + $this->drupalGet('node/1/layout'); + $assert_session->elementsCount('css', '.layout-builder__section', 0); + $assert_session->pageTextContains(sprintf('This layout is being edited by user %s, and is therefore locked from editing by others.', $user2->getDisplayName())); + $assert_session->pageTextNotContains('You have unsaved changes.'); + $assert_session->buttonNotExists('Save layout'); + $assert_session->buttonNotExists('Discard changes'); + $this->drupalGet('layout_builder/configure/section/overrides/node.1/0'); + $assert_session->statusCodeEquals(403); + + // Confirm the tempstore is storing this layout in progress. + $layout_tempstore_before = $this->container->get('tempstore.shared')->get('layout_builder.section_storage.overrides')->getMetadata('node.1.default.en'); + $this->assertNotNull($layout_tempstore_before); + + $this->drupalGet('node/1/layout'); + $page->clickLink('break this lock'); + $page->pressButton('Confirm'); + + // Confirm the tempstore is no longer storing anything for this layout. + $layout_tempstore_after = $this->container->get('tempstore.shared')->get('layout_builder.section_storage.overrides')->getMetadata('node.1.default.en'); + $this->assertNull($layout_tempstore_after); + $assert_session->pageTextNotContains(sprintf('This layout is being edited by user %s, and is therefore locked from editing by others.', $user1->getDisplayName())); + $assert_session->elementsCount('css', '.layout-builder__section', 2); + $assert_session->elementNotExists('css', '.layout--threecol-section'); $assert_session->pageTextNotContains('You have unsaved changes.'); $assert_session->pageTextContains('The changes to the layout have been discarded.'); $assert_session->buttonExists('Save layout'); diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php index dc9d9a7add..b96643d6b6 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/ContextualLinksTest.php @@ -103,7 +103,6 @@ public function testContextualLinks() { protected function addBlock($block_name) { $assert_session = $this->assertSession(); $page = $this->getSession()->getPage(); - $assert_session->linkExists('Add block'); $page->clickLink('Add block'); $assert_session->assertWaitOnAjaxRequest();