File tree Expand file tree Collapse file tree 3 files changed +66
-9
lines changed Expand file tree Collapse file tree 3 files changed +66
-9
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+ /**
3
+ * Plugin for \Magento\Catalog\Model\Category\DataProvider
4
+ *
5
+ * Copyright © Magento, Inc. All rights reserved.
6
+ * See COPYING.txt for license details.
7
+ */
8
+
9
+ declare (strict_types=1 );
10
+
11
+ namespace Magento \Catalog \Model \Plugin ;
12
+
13
+ use Magento \Catalog \Model \Category \DataProvider ;
14
+ use Magento \Framework \Exception \NoSuchEntityException ;
15
+
16
+ /**
17
+ * Sets the default value for Category Design Layout if provided
18
+ */
19
+ class SetPageLayoutDefaultValue
20
+ {
21
+ private $ defaultValue ;
22
+
23
+ /**
24
+ * @param string $defaultValue
25
+ */
26
+ public function __construct (string $ defaultValue = "" )
27
+ {
28
+ $ this ->defaultValue = $ defaultValue ;
29
+ }
30
+
31
+ /**
32
+ * Sets the default value for Category Design Layout in data provider if provided
33
+ *
34
+ * @param DataProvider $subject
35
+ * @param array $result
36
+ * @return array
37
+ *
38
+ * @throws NoSuchEntityException
39
+ */
40
+ public function afterGetDefaultMetaData (DataProvider $ subject , array $ result ): array
41
+ {
42
+ $ currentCategory = $ subject ->getCurrentCategory ();
43
+
44
+ if ($ currentCategory && !$ currentCategory ->getId () && array_key_exists ('page_layout ' , $ result )) {
45
+ $ result ['page_layout ' ]['default ' ] = $ this ->defaultValue ?: null ;
46
+ }
47
+
48
+ return $ result ;
49
+ }
50
+ }
Original file line number Diff line number Diff line change 76
76
<type name =" Magento\Customer\Model\ResourceModel\Visitor" >
77
77
<plugin name =" catalogLog" type =" Magento\Catalog\Model\Plugin\Log" />
78
78
</type >
79
+ <type name =" Magento\Catalog\Model\Category\DataProvider" >
80
+ <plugin name =" set_page_layout_default_value" type =" Magento\Catalog\Model\Plugin\SetPageLayoutDefaultValue" />
81
+ </type >
79
82
<type name =" Magento\Theme\Block\Html\Topmenu" >
80
83
<plugin name =" catalogTopmenu" type =" Magento\Catalog\Plugin\Block\Topmenu" />
81
84
</type >
Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \Ui \Component \Form \Field ;
9
9
10
- use Magento \Framework \View \Element \UiComponentFactory ;
11
- use Magento \Framework \View \Element \UiComponent \ContextInterface ;
12
10
use Magento \Framework \App \Config \ScopeConfigInterface ;
11
+ use Magento \Framework \View \Element \UiComponent \ContextInterface ;
12
+ use Magento \Framework \View \Element \UiComponentFactory ;
13
13
14
- /** Field class has dynamic default value based on System Configuration path */
14
+ /**
15
+ * Field class has dynamic default value based on System Configuration path
16
+ */
15
17
class DefaultValue extends \Magento \Ui \Component \Form \Field
16
18
{
17
19
/**
@@ -55,16 +57,18 @@ public function __construct(
55
57
}
56
58
57
59
/**
58
- * { @inheritdoc}
60
+ * @inheritdoc
59
61
*/
60
62
public function prepare ()
61
63
{
62
64
parent ::prepare ();
63
65
$ store = $ this ->storeManager ->getStore ();
64
- $ this ->_data ['config ' ]['default ' ] = $ this ->scopeConfig ->getValue (
65
- $ this ->path ,
66
- \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
67
- $ store
68
- );
66
+ if (empty ($ this ->_data ['config ' ]['default ' ])) {
67
+ $ this ->_data ['config ' ]['default ' ] = $ this ->scopeConfig ->getValue (
68
+ $ this ->path ,
69
+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
70
+ $ store
71
+ );
72
+ }
69
73
}
70
74
}
You can’t perform that action at this time.
0 commit comments