Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Column.php
Go to the documentation of this file.
1 <?php
7 
12 
17 class Column extends AbstractComponent implements ColumnInterface
18 {
19  const NAME = 'column';
20 
26  protected $wrappedComponent;
27 
34 
43  public function __construct(
46  array $components = [],
47  array $data = []
48  ) {
49  $this->uiComponentFactory = $uiComponentFactory;
50  parent::__construct($context, $components, $data);
51  }
52 
58  public function getComponentName()
59  {
60  return static::NAME . '.' . $this->getData('config/dataType');
61  }
62 
68  public function prepare()
69  {
70  $this->addFieldToSelect();
71 
72  $dataType = $this->getData('config/dataType');
73  if ($dataType) {
74  $this->wrappedComponent = $this->uiComponentFactory->create(
75  $this->getName(),
76  $dataType,
77  array_merge(['context' => $this->getContext()], (array) $this->getData())
78  );
79  $this->wrappedComponent->prepare();
80  $wrappedComponentConfig = $this->getJsConfig($this->wrappedComponent);
81  // Merge JS configuration with wrapped component configuration
82  $jsConfig = array_replace_recursive($wrappedComponentConfig, $this->getJsConfig($this));
83  $this->setData('js_config', $jsConfig);
84 
85  $this->setData(
86  'config',
87  array_replace_recursive(
88  (array)$this->wrappedComponent->getData('config'),
89  (array)$this->getData('config')
90  )
91  );
92  }
93 
94  $this->applySorting();
95 
96  parent::prepare();
97  }
98 
105  public function prepareItems(array & $items)
106  {
107  return $items;
108  }
109 
114  protected function addFieldToSelect()
115  {
116  if ($this->getData('config/add_field')) {
117  $this->getContext()->getDataProvider()->addField($this->getName());
118  }
119  }
120 
126  protected function applySorting()
127  {
128  $sorting = $this->getContext()->getRequestParam('sorting');
129  $isSortable = $this->getData('config/sortable');
130  if ($isSortable !== false
131  && !empty($sorting['field'])
132  && !empty($sorting['direction'])
133  && $sorting['field'] === $this->getName()
134  ) {
135  $this->getContext()->getDataProvider()->addOrder(
136  $this->getName(),
137  strtoupper($sorting['direction'])
138  );
139  }
140  }
141 }
getJsConfig(UiComponentInterface $component)
__construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, array $components=[], array $data=[])
Definition: Column.php:43
$items