Skip to content

Commit e9511e8

Browse files
committed
Replace hard-coded list of category attributes
1 parent 9fa16c7 commit e9511e8

File tree

2 files changed

+28
-50
lines changed

2 files changed

+28
-50
lines changed

app/code/Magento/Catalog/Model/Category/DataProvider.php

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Magento\Eav\Model\Entity\Type;
2323
use Magento\Framework\App\ObjectManager;
2424
use Magento\Framework\App\RequestInterface;
25+
use Magento\Framework\Config\DataInterfaceFactory;
2526
use Magento\Framework\Exception\LocalizedException;
2627
use Magento\Framework\Exception\NoSuchEntityException;
2728
use Magento\Framework\Registry;
@@ -153,6 +154,11 @@ class DataProvider extends ModifierPoolDataProvider
153154
*/
154155
private $categoryFactory;
155156

157+
/**
158+
* @var DataInterfaceFactory
159+
*/
160+
protected $uiConfigFactory;
161+
156162
/**
157163
* @var ScopeOverriddenValue
158164
*/
@@ -193,6 +199,7 @@ class DataProvider extends ModifierPoolDataProvider
193199
* @param Config $eavConfig
194200
* @param RequestInterface $request
195201
* @param CategoryFactory $categoryFactory
202+
* @param DataInterfaceFactory $uiConfigFactory
196203
* @param array $meta
197204
* @param array $data
198205
* @param PoolInterface|null $pool
@@ -215,6 +222,7 @@ public function __construct(
215222
Config $eavConfig,
216223
RequestInterface $request,
217224
CategoryFactory $categoryFactory,
225+
DataInterfaceFactory $uiConfigFactory,
218226
array $meta = [],
219227
array $data = [],
220228
PoolInterface $pool = null,
@@ -233,6 +241,7 @@ public function __construct(
233241
$this->storeManager = $storeManager;
234242
$this->request = $request;
235243
$this->categoryFactory = $categoryFactory;
244+
$this->uiConfigFactory = $uiConfigFactory;
236245
$this->auth = $auth ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
237246
$this->arrayUtils = $arrayUtils ?? ObjectManager::getInstance()->get(ArrayUtils::class);
238247
$this->scopeOverriddenValue = $scopeOverriddenValue ?:
@@ -645,56 +654,22 @@ public function getDefaultMetaData($result)
645654
*/
646655
protected function getFieldsMap()
647656
{
648-
return [
649-
'general' => [
650-
'parent',
651-
'path',
652-
'is_active',
653-
'include_in_menu',
654-
'name',
655-
],
656-
'content' => [
657-
'image',
658-
'description',
659-
'landing_page',
660-
],
661-
'display_settings' => [
662-
'display_mode',
663-
'is_anchor',
664-
'available_sort_by',
665-
'use_config.available_sort_by',
666-
'default_sort_by',
667-
'use_config.default_sort_by',
668-
'filter_price_range',
669-
'use_config.filter_price_range',
670-
],
671-
'search_engine_optimization' => [
672-
'url_key',
673-
'url_key_create_redirect',
674-
'url_key_group',
675-
'meta_title',
676-
'meta_keywords',
677-
'meta_description',
678-
],
679-
'assign_products' => [
680-
],
681-
'design' => [
682-
'custom_use_parent_settings',
683-
'custom_apply_to_products',
684-
'custom_design',
685-
'page_layout',
686-
'custom_layout_update',
687-
'custom_layout_update_file'
688-
],
689-
'schedule_design_update' => [
690-
'custom_design_from',
691-
'custom_design_to',
692-
],
693-
'category_view_optimization' => [
694-
],
695-
'category_permissions' => [
696-
],
697-
];
657+
$referenceName = 'category_form';
658+
$config = $this->uiConfigFactory
659+
->create(['componentName' => $referenceName])
660+
->get($referenceName);
661+
662+
$fieldsMap = [];
663+
664+
if (isset($config['children']) && !empty($config['children'])) {
665+
foreach ($config['children'] as $name => $child) {
666+
if (isset($child['children']) && !empty($child['children'])) {
667+
$fieldsMap[$name] = array_keys($child['children']);
668+
}
669+
}
670+
}
671+
672+
return $fieldsMap;
698673
}
699674

700675
/**

app/code/Magento/Catalog/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@
7979
<plugin name="catalogLog" type="Magento\Catalog\Model\Plugin\Log" />
8080
</type>
8181
<type name="Magento\Catalog\Model\Category\DataProvider">
82+
<arguments>
83+
<argument name="uiConfigFactory" xsi:type="object">uiComponentConfigFactory</argument>
84+
</arguments>
8285
<plugin name="set_page_layout_default_value" type="Magento\Catalog\Model\Plugin\SetPageLayoutDefaultValue" />
8386
</type>
8487
<type name="Magento\Theme\Block\Html\Topmenu">

0 commit comments

Comments
 (0)