Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ColumnFactory.php
Go to the documentation of this file.
1 <?php
7 
11 
13 {
17  protected $componentFactory;
18 
22  protected $inlineEditUpdater;
23 
27  protected $jsComponentMap = [
28  'text' => 'Magento_Ui/js/grid/columns/column',
29  'select' => 'Magento_Ui/js/grid/columns/select',
30  'date' => 'Magento_Ui/js/grid/columns/date',
31  ];
32 
36  protected $dataTypeMap = [
37  'default' => 'text',
38  'text' => 'text',
39  'boolean' => 'select',
40  'select' => 'select',
41  'multiselect' => 'select',
42  'date' => 'date',
43  ];
44 
49  public function __construct(
50  \Magento\Framework\View\Element\UiComponentFactory $componentFactory,
51  InlineEditUpdater $inlineEditor
52  ) {
53  $this->componentFactory = $componentFactory;
54  $this->inlineEditUpdater = $inlineEditor;
55  }
56 
64  public function create(array $attributeData, $columnName, $context, array $config = [])
65  {
66  $config = array_merge([
67  'label' => __($attributeData[AttributeMetadata::FRONTEND_LABEL]),
68  'dataType' => $this->getDataType($attributeData[AttributeMetadata::FRONTEND_INPUT]),
69  'align' => 'left',
70  'visible' => (bool)$attributeData[AttributeMetadata::IS_VISIBLE_IN_GRID],
71  'component' => $this->getJsComponent($this->getDataType($attributeData[AttributeMetadata::FRONTEND_INPUT])),
72  ], $config);
73  if ($attributeData[AttributeMetadata::FRONTEND_INPUT] == 'date') {
74  $config['dateFormat'] = 'MMM d, y';
75  $config['timezone'] = false;
76  }
77  if (count($attributeData[AttributeMetadata::OPTIONS]) && !isset($config[AttributeMetadata::OPTIONS])) {
78  $config[AttributeMetadata::OPTIONS] = $attributeData[AttributeMetadata::OPTIONS];
79  }
80 
81  if ($attributeData[AttributeMetadata::OPTIONS]) {
82  $config['options'] = $attributeData[AttributeMetadata::OPTIONS];
83  }
84  $arguments = [
85  'data' => [
86  'js_config' => [
87  'component' => $this->getJsComponent($config['dataType']),
88  ],
89  'config' => $config,
90  ],
91  'context' => $context,
92  ];
93  $column = $this->componentFactory->create($columnName, 'column', $arguments);
94  $this->inlineEditUpdater->applyEditing(
95  $column,
96  $attributeData[AttributeMetadata::FRONTEND_INPUT],
97  $attributeData[AttributeMetadata::VALIDATION_RULES],
98  $attributeData[AttributeMetadata::REQUIRED]
99  );
100  return $column;
101  }
102 
107  protected function getJsComponent($dataType)
108  {
109  return $this->jsComponentMap[$dataType];
110  }
111 
116  protected function getDataType($frontendType)
117  {
118  return isset($this->dataTypeMap[$frontendType])
119  ? $this->dataTypeMap[$frontendType]
120  : $this->dataTypeMap['default'];
121  }
122 }
$config
Definition: fraud_order.php:17
create(array $attributeData, $columnName, $context, array $config=[])
__()
Definition: __.php:13
$arguments
__construct(\Magento\Framework\View\Element\UiComponentFactory $componentFactory, InlineEditUpdater $inlineEditor)