File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments