3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Widget \Block \Adminhtml \Widget \Instance \Edit \Chooser ;
7
9
10
+ use Magento \Framework \App \ObjectManager ;
11
+ use Magento \Framework \View \Element \Context ;
12
+ use Magento \Framework \View \Element \Html \Select ;
13
+ use Magento \Framework \View \Layout \ProcessorFactory ;
14
+ use Magento \Framework \View \Model \PageLayout \Config \BuilderInterface as PageLayoutConfigBuilder ;
15
+ use Magento \Theme \Model \ResourceModel \Theme \CollectionFactory ;
16
+
8
17
/**
9
18
* A chooser for container for widget instances
10
19
*
13
22
* @method \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Container setTheme($theme)
14
23
* @method \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Container setArea($area)
15
24
*/
16
- class Container extends \ Magento \ Framework \ View \ Element \ Html \ Select
25
+ class Container extends Select
17
26
{
18
27
/**#@+
19
28
* Frontend page layouts
29
+ * @deprecated hardcoded list was replaced with checking actual existing layouts
30
+ * @see \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface::getPageLayoutsConfig
20
31
*/
21
32
const PAGE_LAYOUT_1COLUMN = '1column-center ' ;
22
33
const PAGE_LAYOUT_2COLUMNS_LEFT = '2columns-left ' ;
23
34
const PAGE_LAYOUT_2COLUMNS_RIGHT = '2columns-right ' ;
24
35
const PAGE_LAYOUT_3COLUMNS = '3columns ' ;
25
36
/**#@-*/
26
37
27
- /**#@-*/
38
+ /**
39
+ * @var ProcessorFactory
40
+ */
28
41
protected $ _layoutProcessorFactory ;
29
42
30
43
/**
31
- * @var \Magento\Theme\Model\ResourceModel\Theme\ CollectionFactory
44
+ * @var CollectionFactory
32
45
*/
33
46
protected $ _themesFactory ;
34
47
35
48
/**
36
- * @param \Magento\Framework\View\Element\Context $context
37
- * @param \Magento\Framework\View\Layout\ProcessorFactory $layoutProcessorFactory
38
- * @param \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory $themesFactory
49
+ * @var PageLayoutConfigBuilder
50
+ */
51
+ private $ pageLayoutConfigBuilder ;
52
+
53
+ /**
54
+ * @param Context $context
55
+ * @param ProcessorFactory $layoutProcessorFactory
56
+ * @param CollectionFactory $themesFactory
39
57
* @param array $data
58
+ * @param PageLayoutConfigBuilder|null $pageLayoutConfigBuilder
40
59
*/
41
60
public function __construct (
42
- \Magento \Framework \View \Element \Context $ context ,
43
- \Magento \Framework \View \Layout \ProcessorFactory $ layoutProcessorFactory ,
44
- \Magento \Theme \Model \ResourceModel \Theme \CollectionFactory $ themesFactory ,
45
- array $ data = []
61
+ Context $ context ,
62
+ ProcessorFactory $ layoutProcessorFactory ,
63
+ CollectionFactory $ themesFactory ,
64
+ array $ data = [],
65
+ PageLayoutConfigBuilder $ pageLayoutConfigBuilder = null
46
66
) {
67
+ parent ::__construct ($ context , $ data );
47
68
$ this ->_layoutProcessorFactory = $ layoutProcessorFactory ;
48
69
$ this ->_themesFactory = $ themesFactory ;
49
- parent ::__construct ($ context , $ data );
70
+ $ this ->pageLayoutConfigBuilder = $ pageLayoutConfigBuilder
71
+ ?? ObjectManager::getInstance ()->get (PageLayoutConfigBuilder::class);
50
72
}
51
73
52
74
/**
@@ -101,19 +123,22 @@ protected function _beforeToHtml()
101
123
$ this ->addOption ($ containerName , $ containerLabel );
102
124
}
103
125
}
126
+
104
127
return parent ::_beforeToHtml ();
105
128
}
106
129
107
130
/**
108
131
* Retrieve theme instance by its identifier
109
132
*
110
133
* @param int $themeId
134
+ *
111
135
* @return \Magento\Theme\Model\Theme|null
112
136
*/
113
137
protected function _getThemeInstance ($ themeId )
114
138
{
115
139
/** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection */
116
140
$ themeCollection = $ this ->_themesFactory ->create ();
141
+
117
142
return $ themeCollection ->getItemById ($ themeId );
118
143
}
119
144
@@ -124,11 +149,8 @@ protected function _getThemeInstance($themeId)
124
149
*/
125
150
protected function getPageLayouts ()
126
151
{
127
- return [
128
- self ::PAGE_LAYOUT_1COLUMN ,
129
- self ::PAGE_LAYOUT_2COLUMNS_LEFT ,
130
- self ::PAGE_LAYOUT_2COLUMNS_RIGHT ,
131
- self ::PAGE_LAYOUT_3COLUMNS ,
132
- ];
152
+ $ pageLayoutsConfig = $ this ->pageLayoutConfigBuilder ->getPageLayoutsConfig ();
153
+
154
+ return array_keys ($ pageLayoutsConfig ->getPageLayouts ());
133
155
}
134
156
}
0 commit comments