diff --git a/app/code/Magento/Cms/Model/Page/CustomLayout/CustomLayoutManager.php b/app/code/Magento/Cms/Model/Page/CustomLayout/CustomLayoutManager.php index 988bd5b4ac136..a172278015544 100644 --- a/app/code/Magento/Cms/Model/Page/CustomLayout/CustomLayoutManager.php +++ b/app/code/Magento/Cms/Model/Page/CustomLayout/CustomLayoutManager.php @@ -147,7 +147,8 @@ public function applyUpdate(PageLayout $layout, CustomLayoutSelectedInterface $l } $layout->addPageLayoutHandles( - ['selectable' => $this->sanitizeIdentifier($page) .'_' .$layoutSelected->getLayoutFileId()] + ['selectable' => $this->sanitizeIdentifier($page) .'_' .$layoutSelected->getLayoutFileId()], + 'cms_page_view' ); } } diff --git a/dev/tests/integration/testsuite/Magento/Cms/Controller/PageTest.php b/dev/tests/integration/testsuite/Magento/Cms/Controller/PageTest.php index 4600cd28fd3fc..d80644caca086 100644 --- a/dev/tests/integration/testsuite/Magento/Cms/Controller/PageTest.php +++ b/dev/tests/integration/testsuite/Magento/Cms/Controller/PageTest.php @@ -85,4 +85,20 @@ public function testCustomHandles(): void $handles = $layout->getUpdate()->getHandles(); $this->assertContains('cms_page_view_selectable_test_custom_layout_page_3_test_selected', $handles); } + + /** + * Check home page custom handle is applied when rendering a page. + * + * @return void + * @throws \Throwable + * @magentoDataFixture Magento/Cms/_files/home_with_custom_handle.php + */ + public function testHomePageCustomHandles(): void + { + $this->dispatch('/'); + /** @var LayoutInterface $layout */ + $layout = Bootstrap::getObjectManager()->get(LayoutInterface::class); + $handles = $layout->getUpdate()->getHandles(); + $this->assertContains('cms_page_view_selectable_home_page_custom_layout', $handles); + } } diff --git a/dev/tests/integration/testsuite/Magento/Cms/Model/Page/CustomLayoutManagerTest.php b/dev/tests/integration/testsuite/Magento/Cms/Model/Page/CustomLayoutManagerTest.php index e741b95ff4371..6aa3dcd1c34f9 100644 --- a/dev/tests/integration/testsuite/Magento/Cms/Model/Page/CustomLayoutManagerTest.php +++ b/dev/tests/integration/testsuite/Magento/Cms/Model/Page/CustomLayoutManagerTest.php @@ -97,6 +97,9 @@ public function testCustomLayoutUpdate(): void $result = $this->resultFactory->create(); $this->manager->applyUpdate($result, $this->repo->getFor($pageId)); $this->identityMap->remove((int)$page->getId()); - $this->assertContains('___selectable_page100_select2', $result->getLayout()->getUpdate()->getHandles()); + $this->assertContains( + 'cms_page_view_selectable_page100_select2', + $result->getLayout()->getUpdate()->getHandles() + ); } } diff --git a/dev/tests/integration/testsuite/Magento/Cms/_files/home_with_custom_handle.php b/dev/tests/integration/testsuite/Magento/Cms/_files/home_with_custom_handle.php new file mode 100644 index 0000000000000..2556e0318222d --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Cms/_files/home_with_custom_handle.php @@ -0,0 +1,30 @@ +get(PageModelFactory::class); +/** @var CustomLayoutManager $fakeManager */ +$fakeManager = $objectManager->get(CustomLayoutManager::class); +$layoutRepo = $objectManager->create(PageModel\CustomLayoutRepositoryInterface::class, ['manager' => $fakeManager]); + +$customLayoutName = 'page_custom_layout'; + +/** @var PageModel $page */ +$page = $pageFactory->create(['customLayoutRepository' => $layoutRepo]); +$page->load('home'); +$cmsPageId = (int)$page->getId(); + +$fakeManager->fakeAvailableFiles($cmsPageId, [$customLayoutName]); +$page->setData('layout_update_selected', $customLayoutName); +$page->save(); diff --git a/dev/tests/integration/testsuite/Magento/Cms/_files/home_with_custom_handle_rollback.php b/dev/tests/integration/testsuite/Magento/Cms/_files/home_with_custom_handle_rollback.php new file mode 100644 index 0000000000000..3000e6f85d322 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Cms/_files/home_with_custom_handle_rollback.php @@ -0,0 +1,21 @@ +get(PageRepositoryInterface::class); +$cmsPage = $pageRepository->getById('home'); +$cmsPageId = (int)$cmsPage->getId(); + +/** @var CustomLayoutRepository $customLayoutRepository */ +$customLayoutRepository = $objectManager->get(CustomLayoutRepository::class); +$customLayoutRepository->deleteFor($cmsPageId);