Skip to content

Commit f41f4d4

Browse files
author
silinmykola
committed
32913 set url key for page before validation
1 parent f25fc03 commit f41f4d4

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Model\Plugin\PageRepository;
7+
8+
use Magento\Cms\Api\Data\PageInterface;
9+
use Magento\Cms\Model\PageRepository\ValidationComposite;
10+
use Magento\CmsUrlRewrite\Model\CmsPageUrlPathGenerator;
11+
12+
/**
13+
* Generate url_key if the merchant didn't fill this field
14+
*/
15+
class ValidationCompositePlugin
16+
{
17+
/**
18+
* @var CmsPageUrlPathGenerator
19+
*/
20+
private $cmsPageUrlPathGenerator;
21+
22+
/**
23+
* @param CmsPageUrlPathGenerator $cmsPageUrlPathGenerator
24+
*/
25+
public function __construct(
26+
CmsPageUrlPathGenerator $cmsPageUrlPathGenerator
27+
) {
28+
$this->cmsPageUrlPathGenerator = $cmsPageUrlPathGenerator;
29+
}
30+
31+
/**
32+
* Before save handler
33+
*
34+
* @param ValidationComposite $subject
35+
* @param PageInterface $page
36+
*/
37+
public function beforeSave(
38+
ValidationComposite $subject,
39+
PageInterface $page
40+
) {
41+
$urlKey = $page->getData('identifier');
42+
if ($urlKey === '' || $urlKey === null) {
43+
$page->setData('identifier', $this->cmsPageUrlPathGenerator->generateUrlKey($page));
44+
}
45+
}
46+
}

app/code/Magento/Cms/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@
229229
<type name="Magento\Catalog\Model\Product">
230230
<plugin name="cms" type="Magento\Cms\Model\Plugin\Product" sortOrder="100"/>
231231
</type>
232+
<type name="Magento\Cms\Model\PageRepository\ValidationComposite">
233+
<plugin name="cms_validate_url_plugin" type="Magento\Cms\Model\Plugin\PageRepository\ValidationCompositePlugin" sortOrder="10"/>
234+
</type>
232235
<type name="Magento\Cms\Model\PageRepository\ValidationComposite">
233236
<arguments>
234237
<argument name="repository" xsi:type="object">Magento\Cms\Model\PageRepository</argument>

0 commit comments

Comments
 (0)