Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeReader.php
Go to the documentation of this file.
1 <?php
8 
15 
20 {
24  private $mapper;
25 
29  private $typeLocator;
30 
34  private $collection;
35 
41  public function __construct(
42  MapperInterface $mapper,
43  Type $typeLocator,
44  Collection $collection
45  ) {
46  $this->mapper = $mapper;
47  $this->typeLocator = $typeLocator;
48  $this->collection = $collection;
49  }
50 
59  public function read($scope = null) : array
60  {
61  $typeNames = $this->mapper->getMappedTypes(\Magento\Catalog\Model\Product::ENTITY);
62  $config =[];
64  foreach ($this->collection->getAttributes() as $attribute) {
65  $attributeCode = $attribute->getAttributeCode();
66  $locatedType = $this->typeLocator->getType(
68  \Magento\Catalog\Model\Product::ENTITY
69  ) ?: 'String';
70  $locatedType = $locatedType === TypeProcessor::NORMALIZED_ANY_TYPE ? 'String' : ucfirst($locatedType);
71  foreach ($typeNames as $typeName) {
72  $config[$typeName]['fields'][$attributeCode] = [
73  'name' => $attributeCode,
74  'type' => $locatedType,
75  'arguments' => []
76  ];
77  }
78  }
79 
80  return $config;
81  }
82 }
$config
Definition: fraud_order.php:17
__construct(MapperInterface $mapper, Type $typeLocator, Collection $collection)
$attributeCode
Definition: extend.phtml:12