File tree 2 files changed +52
-0
lines changed
app/code/Magento/CmsUrlRewrite
2 files changed +52
-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
+ declare (strict_types=1 );
7
+
8
+ namespace Magento \CmsUrlRewrite \Plugin \Cms \Model \PageRepository ;
9
+
10
+ use Magento \Cms \Api \Data \PageInterface ;
11
+ use Magento \Cms \Model \PageRepository \ValidationComposite ;
12
+ use Magento \CmsUrlRewrite \Model \CmsPageUrlPathGenerator ;
13
+
14
+ /**
15
+ * Generate url_key if the merchant didn't fill this field
16
+ */
17
+ class ValidationCompositePlugin
18
+ {
19
+ /**
20
+ * @var CmsPageUrlPathGenerator
21
+ */
22
+ private $ cmsPageUrlPathGenerator ;
23
+
24
+ /**
25
+ * @param CmsPageUrlPathGenerator $cmsPageUrlPathGenerator
26
+ */
27
+ public function __construct (
28
+ CmsPageUrlPathGenerator $ cmsPageUrlPathGenerator
29
+ ) {
30
+ $ this ->cmsPageUrlPathGenerator = $ cmsPageUrlPathGenerator ;
31
+ }
32
+
33
+ /**
34
+ * Before save handler
35
+ *
36
+ * @param ValidationComposite $subject
37
+ * @param PageInterface $page
38
+ */
39
+ public function beforeSave (
40
+ ValidationComposite $ subject ,
41
+ PageInterface $ page
42
+ ) {
43
+ $ urlKey = $ page ->getData ('identifier ' );
44
+ if ($ urlKey === '' || $ urlKey === null ) {
45
+ $ page ->setData ('identifier ' , $ this ->cmsPageUrlPathGenerator ->generateUrlKey ($ page ));
46
+ }
47
+ }
48
+ }
Original file line number Diff line number Diff line change 9
9
<type name =" Magento\Cms\Model\ResourceModel\Page" >
10
10
<plugin name =" cms_url_rewrite_plugin" type =" Magento\CmsUrlRewrite\Plugin\Cms\Model\ResourceModel\Page" />
11
11
</type >
12
+ <type name =" Magento\Cms\Model\PageRepository\ValidationComposite" >
13
+ <plugin name =" cms_validate_url_plugin"
14
+ type =" Magento\CmsUrlRewrite\Plugin\Cms\Model\PageRepository\ValidationCompositePlugin" sortOrder =" 10" />
15
+ </type >
12
16
<type name =" Magento\UrlRewrite\Model\UrlRewrite" >
13
17
<arguments >
14
18
<argument name =" entityToCacheTagMap" xsi : type =" array" >
You can’t perform that action at this time.
0 commit comments