Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CategoryAttributeReader.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
10 use Magento\Catalog\Model\ResourceModel\Category\Attribute\CollectionFactory;
16 
21 {
28  private static $bannedSystemAttributes = [
29  'position',
30  'is_active',
31  'children',
32  'level',
33  'default_sort_by',
34  'all_children',
35  'page_layout',
36  'custom_design',
37  'custom_design_from',
38  'custom_design_to',
39  'custom_layout_update',
40  'custom_use_parent_settings',
41  'custom_apply_to_products',
42  ];
43 
47  private $typeLocator;
48 
52  private $collectionFactory;
53 
58  public function __construct(
59  Type $typeLocator,
60  CollectionFactory $collectionFactory
61  ) {
62  $this->typeLocator = $typeLocator;
63  $this->collectionFactory = $collectionFactory;
64  }
65 
74  public function read($scope = null) : array
75  {
76  $config =[];
77  $data = [];
79  $collection = $this->collectionFactory->create();
81  foreach ($collection as $attribute) {
82  $attributeCode = $attribute->getAttributeCode();
83 
84  if (in_array($attributeCode, self::$bannedSystemAttributes)) {
85  continue;
86  }
87 
88  $locatedType = $this->typeLocator->getType(
90  'catalog_category'
91  ) ?: 'String';
92  $locatedType = $locatedType === TypeProcessor::NORMALIZED_ANY_TYPE ? 'String' : ucfirst($locatedType);
93  $data['fields'][$attributeCode]['name'] = $attributeCode;
94  $data['fields'][$attributeCode]['type'] = $locatedType;
95  $data['fields'][$attributeCode]['arguments'] = [];
96  }
97 
98  $config['CategoryInterface'] = $data;
99  $config['CategoryTree'] = $data;
100 
101  return $config;
102  }
103 }
$config
Definition: fraud_order.php:17
__construct(Type $typeLocator, CollectionFactory $collectionFactory)
$attributeCode
Definition: extend.phtml:12