Skip to content

Commit 8d3d2c9

Browse files
committed
MC-41018: Minor changes in CMS page validation
1 parent eeeb85a commit 8d3d2c9

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

app/code/Magento/Cms/Model/Page/CustomLayout/CustomLayoutValidator.php

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
use Magento\Framework\Exception\LocalizedException;
1111
use Magento\Framework\Message\ManagerInterface;
12-
use Magento\Cms\Model\PageFactory;
12+
use Magento\Cms\Model\PageRepository;
1313

14+
/**
15+
* Class for layout update validation
16+
*/
1417
class CustomLayoutValidator
1518
{
1619
/**
@@ -25,11 +28,11 @@ class CustomLayoutValidator
2528

2629
/**
2730
* CustomLayoutValidator constructor.
28-
* @param PageFactory $pageFactory
31+
* @param PageRepository $pageFactory
2932
* @param ManagerInterface $messageManager
3033
*/
3134
public function __construct(
32-
PageFactory $pageFactory,
35+
PageRepository $pageFactory,
3336
ManagerInterface $messageManager
3437
) {
3538
$this->pageFactory = $pageFactory;
@@ -43,18 +46,23 @@ public function __construct(
4346
* @return bool
4447
* @throws LocalizedException
4548
*/
46-
public function validate(array $data)
49+
public function validate(array $data) : bool
4750
{
4851
$layoutUpdate = isset($data['layout_update_xml']) ? $data['layout_update_xml'] : null;
4952
$customLayoutUpdate = isset($data['custom_layout_update_xml']) ? $data['custom_layout_update_xml'] : null;
50-
$page = $this->pageFactory->create();
51-
$page->load($data['page_id']);
52-
$oldLayoutUpdate = $page->getId() ? $page->getLayoutUpdateXml() : null;
53-
$olCustomLayoutUpdate = $page->getId() ? $page->getCustomLayoutUpdateXml() : null;
54-
if ($layoutUpdate && $oldLayoutUpdate !== $layoutUpdate
55-
|| $customLayoutUpdate && $olCustomLayoutUpdate !== $customLayoutUpdate
56-
) {
57-
throw new LocalizedException(__('Custom layout update text cannot be changed, only removed'));
53+
if (isset($data['page_id'])) {
54+
$page = $this->pageFactory->getById($data['page_id']);
55+
$oldLayoutUpdate = $page->getId() ? $page->getLayoutUpdateXml() : null;
56+
$oldCustomLayoutUpdate = $page->getId() ? $page->getCustomLayoutUpdateXml() : null;
57+
if ($layoutUpdate && $oldLayoutUpdate !== $layoutUpdate
58+
|| $customLayoutUpdate && $oldCustomLayoutUpdate !== $customLayoutUpdate
59+
) {
60+
throw new LocalizedException(__('Custom layout update text cannot be changed, only removed'));
61+
}
62+
} else {
63+
if ($layoutUpdate || $customLayoutUpdate) {
64+
throw new LocalizedException(__('Custom layout update text cannot be changed, only removed'));
65+
}
5866
}
5967
return true;
6068
}

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/PageDesignTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ class PageDesignTest extends AbstractBackendController
6565
*/
6666
private $pagesToDelete = [];
6767

68-
private $postDaraProcessor;
68+
/**
69+
* @var PostDataProcessor
70+
*/
71+
private $postDataProcessor;
6972

7073
/**
7174
* @inheritDoc
@@ -84,7 +87,7 @@ protected function setUp(): void
8487
$this->pageRetriever = Bootstrap::getObjectManager()->get(GetPageByIdentifierInterface::class);
8588
$this->scopeConfig = Bootstrap::getObjectManager()->get(ScopeConfigInterface::class);
8689
$this->pagesToDelete = [];
87-
$this->postDaraProcessor = Bootstrap::getObjectManager()->get(PostDataProcessor::class);
90+
$this->postDataProcessor = Bootstrap::getObjectManager()->get(PostDataProcessor::class);
8891
}
8992

9093
/**
@@ -315,6 +318,6 @@ public function testSaveWithCustomLayoutUpdate(): void
315318
PageInterface::CUSTOM_LAYOUT_UPDATE_XML => '<container />',
316319
PageInterface::LAYOUT_UPDATE_XML => '<container />',
317320
];
318-
$this->assertFalse($this->postDaraProcessor->validate($requestData));
321+
$this->assertFalse($this->postDataProcessor->validate($requestData));
319322
}
320323
}

0 commit comments

Comments
 (0)