Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StaticField.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15  as FieldTypeConverterInterface;
17  as IndexTypeConverterInterface;
19  as FieldTypeResolver;
21  as FieldIndexResolver;
22 
27 {
31  private $eavConfig;
32 
36  private $fieldTypeConverter;
37 
41  private $indexTypeConverter;
42 
46  private $attributeAdapterProvider;
47 
51  private $fieldTypeResolver;
52 
56  private $fieldIndexResolver;
57 
66  public function __construct(
67  Config $eavConfig,
68  FieldTypeConverterInterface $fieldTypeConverter,
69  IndexTypeConverterInterface $indexTypeConverter,
70  FieldTypeResolver $fieldTypeResolver,
71  FieldIndexResolver $fieldIndexResolver,
72  AttributeProvider $attributeAdapterProvider
73  ) {
74  $this->eavConfig = $eavConfig;
75  $this->fieldTypeConverter = $fieldTypeConverter;
76  $this->indexTypeConverter = $indexTypeConverter;
77  $this->fieldTypeResolver = $fieldTypeResolver;
78  $this->fieldIndexResolver = $fieldIndexResolver;
79  $this->attributeAdapterProvider = $attributeAdapterProvider;
80  }
81 
88  public function getFields(array $context = []): array
89  {
90  $attributes = $this->eavConfig->getEntityAttributes(ProductAttributeInterface::ENTITY_TYPE_CODE);
91  $allAttributes = [];
92 
93  foreach ($attributes as $attribute) {
94  $attributeAdapter = $this->attributeAdapterProvider->getByAttributeCode($attribute->getAttributeCode());
95  $code = $attributeAdapter->getAttributeCode();
96 
97  $allAttributes[$code] = [
98  'type' => $this->fieldTypeResolver->getFieldType($attributeAdapter),
99  ];
100 
101  $index = $this->fieldIndexResolver->getFieldIndex($attributeAdapter);
102  if (null !== $index) {
103  $allAttributes[$code]['index'] = $index;
104  }
105 
106  if ($attributeAdapter->isComplexType()) {
107  $allAttributes[$code . '_value'] = [
108  'type' => $this->fieldTypeConverter->convert(FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING)
109  ];
110  }
111  }
112 
113  $allAttributes['store_id'] = [
114  'type' => $this->fieldTypeConverter->convert(FieldTypeConverterInterface::INTERNAL_DATA_TYPE_STRING),
115  'index' => $this->indexTypeConverter->convert(IndexTypeConverterInterface::INTERNAL_NO_INDEX_VALUE),
116  ];
117 
118  return $allAttributes;
119  }
120 }
__construct(Config $eavConfig, FieldTypeConverterInterface $fieldTypeConverter, IndexTypeConverterInterface $indexTypeConverter, FieldTypeResolver $fieldTypeResolver, FieldIndexResolver $fieldIndexResolver, AttributeProvider $attributeAdapterProvider)
Definition: StaticField.php:66
$attributes
Definition: matrix.phtml:13
$index
Definition: list.phtml:44
$code
Definition: info.phtml:12