Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Theme.php
Go to the documentation of this file.
1 <?php
11 
12 class Theme extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilter
13 {
17  protected $_labelFactory;
18 
25  public function __construct(
26  \Magento\Backend\Block\Context $context,
27  \Magento\Framework\DB\Helper $resourceHelper,
28  \Magento\Framework\View\Design\Theme\LabelFactory $labelFactory,
29  array $data = []
30  ) {
31  $this->_labelFactory = $labelFactory;
32  parent::__construct($context, $resourceHelper, $data);
33  }
34 
40  public function getHtml()
41  {
42  $options = $this->getOptions();
43  if ($this->getColumn()->getWithEmpty()) {
44  array_unshift($options, ['value' => '', 'label' => '']);
45  }
46  $html = sprintf(
47  '<select name="%s" id="%s" class="admin__control-select no-changes" %s>%s</select>',
48  $this->_getHtmlName(),
49  $this->_getHtmlId(),
50  $this->getUiId('filter', $this->_getHtmlName()),
51  $this->_drawOptions($options)
52  );
53  return $html;
54  }
55 
62  public function getOptions()
63  {
64  $options = $this->getColumn()->getOptions();
65  if (empty($options) || !is_array($options)) {
67  $label = $this->_labelFactory->create();
68  $options = $label->getLabelsCollection();
69  }
70  return $options;
71  }
72 
79  protected function _drawOptions($options)
80  {
81  if (empty($options) || !is_array($options)) {
82  return '';
83  }
84 
85  $value = $this->getValue();
86  $html = '';
87 
88  foreach ($options as $option) {
89  if (!isset($option['value']) || !isset($option['label'])) {
90  continue;
91  }
92  if (is_array($option['value'])) {
93  $html .= '<optgroup label="' . $option['label'] . '">' . $this->_drawOptions(
94  $option['value']
95  ) . '</optgroup>';
96  } else {
97  $selected = $option['value'] == $value && $value !== null ? ' selected="selected"' : '';
98  $html .= '<option value="' . $option['value'] . '"' . $selected . '>' . $option['label'] . '</option>';
99  }
100  }
101 
102  return $html;
103  }
104 
110  public function getCondition()
111  {
112  if ($this->getValue() === null) {
113  return null;
114  }
115  $value = $this->getValue();
116  if ($value == 'all') {
117  $value = '';
118  }
119  return ['eq' => $value];
120  }
121 }
getUiId($arg1=null, $arg2=null, $arg3=null, $arg4=null, $arg5=null)
__construct(\Magento\Backend\Block\Context $context, \Magento\Framework\DB\Helper $resourceHelper, \Magento\Framework\View\Design\Theme\LabelFactory $labelFactory, array $data=[])
Definition: Theme.php:25
$label
Definition: details.phtml:21
$value
Definition: gender.phtml:16