33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
7+
68namespace Magento \Widget \Block \Adminhtml \Widget \Instance \Edit \Chooser ;
79
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+
817/**
918 * A chooser for container for widget instances
1019 *
1322 * @method \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Container setTheme($theme)
1423 * @method \Magento\Widget\Block\Adminhtml\Widget\Instance\Edit\Chooser\Container setArea($area)
1524 */
16- class Container extends \ Magento \ Framework \ View \ Element \ Html \ Select
25+ class Container extends Select
1726{
1827 /**#@+
1928 * Frontend page layouts
29+ * @deprecated hardcoded list was replaced with checking actual existing layouts
30+ * @see \Magento\Framework\View\Model\PageLayout\Config\BuilderInterface::getPageLayoutsConfig
2031 */
2132 const PAGE_LAYOUT_1COLUMN = '1column-center ' ;
2233 const PAGE_LAYOUT_2COLUMNS_LEFT = '2columns-left ' ;
2334 const PAGE_LAYOUT_2COLUMNS_RIGHT = '2columns-right ' ;
2435 const PAGE_LAYOUT_3COLUMNS = '3columns ' ;
2536 /**#@-*/
2637
27- /**#@-*/
38+ /**
39+ * @var ProcessorFactory
40+ */
2841 protected $ _layoutProcessorFactory ;
2942
3043 /**
31- * @var \Magento\Theme\Model\ResourceModel\Theme\ CollectionFactory
44+ * @var CollectionFactory
3245 */
3346 protected $ _themesFactory ;
3447
3548 /**
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
3957 * @param array $data
58+ * @param PageLayoutConfigBuilder|null $pageLayoutConfigBuilder
4059 */
4160 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
4666 ) {
67+ parent ::__construct ($ context , $ data );
4768 $ this ->_layoutProcessorFactory = $ layoutProcessorFactory ;
4869 $ this ->_themesFactory = $ themesFactory ;
49- parent ::__construct ($ context , $ data );
70+ $ this ->pageLayoutConfigBuilder = $ pageLayoutConfigBuilder
71+ ?? ObjectManager::getInstance ()->get (PageLayoutConfigBuilder::class);
5072 }
5173
5274 /**
@@ -101,19 +123,22 @@ protected function _beforeToHtml()
101123 $ this ->addOption ($ containerName , $ containerLabel );
102124 }
103125 }
126+
104127 return parent ::_beforeToHtml ();
105128 }
106129
107130 /**
108131 * Retrieve theme instance by its identifier
109132 *
110133 * @param int $themeId
134+ *
111135 * @return \Magento\Theme\Model\Theme|null
112136 */
113137 protected function _getThemeInstance ($ themeId )
114138 {
115139 /** @var \Magento\Theme\Model\ResourceModel\Theme\Collection $themeCollection */
116140 $ themeCollection = $ this ->_themesFactory ->create ();
141+
117142 return $ themeCollection ->getItemById ($ themeId );
118143 }
119144
@@ -124,11 +149,8 @@ protected function _getThemeInstance($themeId)
124149 */
125150 protected function getPageLayouts ()
126151 {
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 ());
133155 }
134156}
0 commit comments