22
22
use Magento \Eav \Model \Entity \Type ;
23
23
use Magento \Framework \App \ObjectManager ;
24
24
use Magento \Framework \App \RequestInterface ;
25
+ use Magento \Framework \AuthorizationInterface ;
26
+ use Magento \Framework \Config \DataInterfaceFactory ;
25
27
use Magento \Framework \Exception \LocalizedException ;
26
28
use Magento \Framework \Exception \NoSuchEntityException ;
27
29
use Magento \Framework \Registry ;
32
34
use Magento \Ui \Component \Form \Field ;
33
35
use Magento \Ui \DataProvider \EavValidationRules ;
34
36
use Magento \Ui \DataProvider \Modifier \PoolInterface ;
35
- use Magento \Framework \AuthorizationInterface ;
36
37
use Magento \Ui \DataProvider \ModifierPoolDataProvider ;
37
38
38
39
/**
@@ -153,6 +154,11 @@ class DataProvider extends ModifierPoolDataProvider
153
154
*/
154
155
private $ categoryFactory ;
155
156
157
+ /**
158
+ * @var DataInterfaceFactory
159
+ */
160
+ private $ uiConfigFactory ;
161
+
156
162
/**
157
163
* @var ScopeOverriddenValue
158
164
*/
@@ -177,6 +183,7 @@ class DataProvider extends ModifierPoolDataProvider
177
183
* @var AuthorizationInterface
178
184
*/
179
185
private $ auth ;
186
+
180
187
/**
181
188
* @var Image
182
189
*/
@@ -202,6 +209,7 @@ class DataProvider extends ModifierPoolDataProvider
202
209
* @param ArrayManager|null $arrayManager
203
210
* @param FileInfo|null $fileInfo
204
211
* @param Image|null $categoryImage
212
+ * @param DataInterfaceFactory|null $uiConfigFactory
205
213
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
206
214
*/
207
215
public function __construct (
@@ -223,7 +231,8 @@ public function __construct(
223
231
ScopeOverriddenValue $ scopeOverriddenValue = null ,
224
232
ArrayManager $ arrayManager = null ,
225
233
FileInfo $ fileInfo = null ,
226
- ?Image $ categoryImage = null
234
+ ?Image $ categoryImage = null ,
235
+ ?DataInterfaceFactory $ uiConfigFactory = null
227
236
) {
228
237
$ this ->eavValidationRules = $ eavValidationRules ;
229
238
$ this ->collection = $ categoryCollectionFactory ->create ();
@@ -240,6 +249,10 @@ public function __construct(
240
249
$ this ->arrayManager = $ arrayManager ?: ObjectManager::getInstance ()->get (ArrayManager::class);
241
250
$ this ->fileInfo = $ fileInfo ?: ObjectManager::getInstance ()->get (FileInfo::class);
242
251
$ this ->categoryImage = $ categoryImage ?? ObjectManager::getInstance ()->get (Image::class);
252
+ $ this ->uiConfigFactory = $ uiConfigFactory ?? ObjectManager::getInstance ()->create (
253
+ DataInterfaceFactory::class,
254
+ ['instanceName ' => \Magento \Ui \Config \Data::class]
255
+ );
243
256
244
257
parent ::__construct ($ name , $ primaryFieldName , $ requestFieldName , $ meta , $ data , $ pool );
245
258
}
@@ -611,7 +624,7 @@ private function convertValues($category, $categoryData): array
611
624
612
625
$ categoryData [$ attributeCode ][0 ]['url ' ] = $ this ->categoryImage ->getUrl ($ category , $ attributeCode );
613
626
614
- $ categoryData [$ attributeCode ][0 ]['size ' ] = isset ( $ stat) ? $ stat ['size ' ] : 0 ;
627
+ $ categoryData [$ attributeCode ][0 ]['size ' ] = $ stat ['size ' ];
615
628
$ categoryData [$ attributeCode ][0 ]['type ' ] = $ mime ;
616
629
}
617
630
}
@@ -645,56 +658,42 @@ public function getDefaultMetaData($result)
645
658
*/
646
659
protected function getFieldsMap ()
647
660
{
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
- ];
661
+ $ referenceName = 'category_form ' ;
662
+ $ config = $ this ->uiConfigFactory
663
+ ->create (['componentName ' => $ referenceName ])
664
+ ->get ($ referenceName );
665
+
666
+ if (empty ($ config )) {
667
+ return [];
668
+ }
669
+
670
+ $ fieldsMap = [];
671
+
672
+ foreach ($ config ['children ' ] as $ group => $ node ) {
673
+ // Skip disabled components (required for Commerce Edition)
674
+ if ($ node ['arguments ' ]['data ' ]['config ' ]['componentDisabled ' ] ?? false ) {
675
+ continue ;
676
+ }
677
+
678
+ $ fields = [];
679
+
680
+ foreach ($ node ['children ' ] as $ childName => $ childNode ) {
681
+ if (!empty ($ childNode ['children ' ])) {
682
+ // <container/> nodes need special handling
683
+ foreach (array_keys ($ childNode ['children ' ]) as $ grandchildName ) {
684
+ $ fields [] = $ grandchildName ;
685
+ }
686
+ } else {
687
+ $ fields [] = $ childName ;
688
+ }
689
+ }
690
+
691
+ if (!empty ($ fields )) {
692
+ $ fieldsMap [$ group ] = $ fields ;
693
+ }
694
+ }
695
+
696
+ return $ fieldsMap ;
698
697
}
699
698
700
699
/**
0 commit comments