diff --git a/core/modules/layout_builder/src/Controller/LayoutBuilderController.php b/core/modules/layout_builder/src/Controller/LayoutBuilderController.php index 0f2c627e86..c9ccc20086 100644 --- a/core/modules/layout_builder/src/Controller/LayoutBuilderController.php +++ b/core/modules/layout_builder/src/Controller/LayoutBuilderController.php @@ -386,21 +386,4 @@ public function saveLayout(SectionStorageInterface $section_storage) { return new RedirectResponse($section_storage->getRedirectUrl()->setAbsolute()->toString()); } - /** - * Cancels the layout. - * - * @param \Drupal\layout_builder\SectionStorageInterface $section_storage - * The section storage. - * - * @return \Symfony\Component\HttpFoundation\RedirectResponse - * A redirect response. - */ - public function cancelLayout(SectionStorageInterface $section_storage) { - $this->layoutTempstoreRepository->delete($section_storage); - - $this->messenger->addMessage($this->t('The changes to the layout have been discarded.')); - - return new RedirectResponse($section_storage->getRedirectUrl()->setAbsolute()->toString()); - } - } diff --git a/core/modules/layout_builder/src/Form/CancelLayoutForm.php b/core/modules/layout_builder/src/Form/CancelLayoutForm.php index 2812d91320..63ac0b21d4 100644 --- a/core/modules/layout_builder/src/Form/CancelLayoutForm.php +++ b/core/modules/layout_builder/src/Form/CancelLayoutForm.php @@ -103,7 +103,8 @@ public function getCancelUrl() { */ public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL) { $this->sectionStorage = $section_storage; - $this->isOwnerCurrentUser = $this->layoutTempstoreRepository->getLock($section_storage)->getOwnerId() === $this->currentUser()->id(); + $lock = $this->layoutTempstoreRepository->getLock($section_storage); + $this->isOwnerCurrentUser = $lock && $lock->getOwnerId() === $this->currentUser()->id(); return parent::buildForm($form, $form_state); } diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php index 9b9a82e418..9d2f33ff67 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php @@ -307,6 +307,7 @@ public function testNonDefaultViewMode() { // Confirm the body field only is shown once. $assert_session->elementsCount('css', '.field--name-body', 1); $this->clickLink('Cancel Layout'); + $page->pressButton('Confirm'); $this->clickLink('Teaser'); // Enabling Layout Builder for the default mode does not affect the teaser. @@ -322,6 +323,7 @@ public function testNonDefaultViewMode() { // Enable a disabled view mode. $page->clickLink('Cancel Layout'); + $page->pressButton('Confirm'); $assert_session->addressEquals("$field_ui_prefix/display/teaser"); $page->clickLink('Default'); $assert_session->addressEquals("$field_ui_prefix/display"); @@ -452,6 +454,7 @@ public function testLayoutBuilderUiFullViewMode() { $this->drupalGet('node/1/layout'); $assert_session->pageTextContains('This is the default view mode'); $this->clickLink('Cancel Layout'); + $page->pressButton('Confirm'); // Enable the full view mode and customize it. $this->drupalPostForm("$field_ui_prefix/display/default", ['display_modes_custom[full]' => TRUE], 'Save'); @@ -471,6 +474,7 @@ public function testLayoutBuilderUiFullViewMode() { $this->drupalGet('node/1/layout'); $assert_session->pageTextContains('This is the full view mode'); $this->clickLink('Cancel Layout'); + $page->pressButton('Confirm'); // Disable the full view mode, the default should be used again. $this->drupalPostForm("$field_ui_prefix/display/default", ['display_modes_custom[full]' => FALSE], 'Save'); @@ -479,6 +483,7 @@ public function testLayoutBuilderUiFullViewMode() { $this->drupalGet('node/1/layout'); $assert_session->pageTextContains('This is the default view mode'); $this->clickLink('Cancel Layout'); + $page->pressButton('Confirm'); } /** diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php index 4f463192d1..3cd1786cfc 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/InlineBlockTest.php @@ -176,7 +176,7 @@ public function layoutNoSaveProvider() { 'cancel' => [ 'cancel', 'Cancel Layout', - NULL, + 'Confirm', ], 'revert' => [ 'revert', diff --git a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php index c5510e9d5f..ca451769a6 100644 --- a/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php +++ b/core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderUiTest.php @@ -60,6 +60,7 @@ public function testUnsavedChangesMessage() { // Make and then cancel changes. $this->assertModifiedLayout(static::FIELD_UI_PREFIX . '/display-layout/default'); $page->clickLink('Cancel Layout'); + $page->pressButton('Confirm'); $assert_session->pageTextNotContains('You have unsaved changes.'); // Make and then save changes. diff --git a/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php b/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php index ab7b7e8ec0..5212442fab 100644 --- a/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Unit/DefaultsSectionStorageTest.php @@ -426,7 +426,7 @@ public function testBuildRoutes() { 'bundle_key' => 'my_bundle_type', 'section_storage_type' => 'defaults', 'section_storage' => '', - '_controller' => '\Drupal\layout_builder\Controller\LayoutBuilderController::cancelLayout', + '_form' => '\Drupal\layout_builder\Form\CancelLayoutForm', ], [ '_field_ui_view_mode_access' => 'administer with_bundle_key display', @@ -511,7 +511,7 @@ public function testBuildRoutes() { 'entity_type_id' => 'with_bundle_parameter', 'section_storage_type' => 'defaults', 'section_storage' => '', - '_controller' => '\Drupal\layout_builder\Controller\LayoutBuilderController::cancelLayout', + '_form' => '\Drupal\layout_builder\Form\CancelLayoutForm', ], [ '_field_ui_view_mode_access' => 'administer with_bundle_parameter display', diff --git a/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php b/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php index 6ea0c4bc43..92d3dbf0af 100644 --- a/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Unit/OverridesSectionStorageTest.php @@ -349,7 +349,7 @@ public function testBuildRoutes() { 'entity_type_id' => 'with_string_id', 'section_storage_type' => 'overrides', 'section_storage' => '', - '_controller' => '\Drupal\layout_builder\Controller\LayoutBuilderController::cancelLayout', + '_form' => '\Drupal\layout_builder\Form\CancelLayoutForm', ], [ '_has_layout_section' => 'true', @@ -433,7 +433,7 @@ public function testBuildRoutes() { 'entity_type_id' => 'with_integer_id', 'section_storage_type' => 'overrides', 'section_storage' => '', - '_controller' => '\Drupal\layout_builder\Controller\LayoutBuilderController::cancelLayout', + '_form' => '\Drupal\layout_builder\Form\CancelLayoutForm', ], [ '_has_layout_section' => 'true',