Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Filters.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Ui\Component;
7 
13 
19 {
20  const NAME = 'filters';
21 
27  protected $columnFilters = [];
28 
34  protected $filterMap = [
35  'text' => 'filterInput',
36  'textRange' => 'filterRange',
37  'select' => 'filterSelect',
38  'dateRange' => 'filterDate',
39  ];
40 
45 
49  public function __construct(
52  array $components = [],
53  array $data = []
54  ) {
55  parent::__construct($context, $components, $data);
56  $this->uiComponentFactory = $uiComponentFactory;
57  }
58 
64  public function getComponentName()
65  {
66  return static::NAME;
67  }
68 
72  public function update(UiComponentInterface $component)
73  {
74  if ($component instanceof ColumnInterface) {
75  $filterType = $component->getData('config/filter');
76 
77  if (is_array($filterType)) {
78  $filterType = $filterType['filterType'];
79  }
80 
81  if (!$filterType) {
82  return;
83  }
84 
85  if (isset($this->filterMap[$filterType]) && !isset($this->columnFilters[$component->getName()])) {
86  $filterComponent = $this->uiComponentFactory->create(
87  $component->getName(),
88  $this->filterMap[$filterType],
89  ['context' => $this->getContext()]
90  );
91  $filterComponent->setData('config', $component->getConfiguration());
92  $filterComponent->prepare();
93  $this->addComponent($component->getName(), $filterComponent);
94  }
95  }
96  }
97 
101  public function addComponent($name, UiComponentInterface $component)
102  {
103  $this->columnFilters[$name] = $component;
104  parent::addComponent($name, $component);
105  }
106 
110  public function getChildComponents()
111  {
112  $result = parent::getChildComponents();
113  foreach (array_keys($this->columnFilters) as $componentName) {
114  if ($this->getComponent($componentName)) {
115  unset($result[$componentName]);
116  }
117  }
118 
119  return $result;
120  }
121 }
update(UiComponentInterface $component)
Definition: Filters.php:72
addComponent($name, UiComponentInterface $component)
Definition: Filters.php:101
__construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, array $components=[], array $data=[])
Definition: Filters.php:49
if(!isset($_GET['name'])) $name
Definition: log.php:14