Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AttributeColumn.php
Go to the documentation of this file.
1 <?php
7 
13 
14 class AttributeColumn extends Column
15 {
20 
28  public function __construct(
32  array $components = [],
33  array $data = []
34  ) {
35  parent::__construct($context, $uiComponentFactory, $components, $data);
36  $this->attributeRepository = $attributeRepository;
37  }
38 
45  public function prepareDataSource(array $dataSource)
46  {
47  $metaData = $this->attributeRepository->getMetadataByCode($this->getName());
48  if ($metaData && count($metaData[AttributeMetadata::OPTIONS])) {
49  foreach ($dataSource['data']['items'] as &$item) {
50  if (!isset($item[$this->getName()])) {
51  continue;
52  }
53  foreach ($metaData[AttributeMetadata::OPTIONS] as $option) {
54  if ($option['value'] == $item[$this->getName()]) {
55  $item[$this->getName()] = $option['label'];
56  break;
57  }
58  }
59  }
60  }
61 
62  return $dataSource;
63  }
64 }
__construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, AttributeRepository $attributeRepository, array $components=[], array $data=[])