Same name and namespace in other branches
- 8.9.x core/modules/views/src/Plugin/views/filter/ManyToOne.php \Drupal\views\Plugin\views\filter\ManyToOne
- 9 core/modules/views/src/Plugin/views/filter/ManyToOne.php \Drupal\views\Plugin\views\filter\ManyToOne
Hierarchy
- class \Drupal\views\Plugin\views\filter\InOperator extends \Drupal\views\Plugin\views\filter\FilterPluginBase implements FilterOperatorsInterface
- class \Drupal\views\Plugin\views\filter\ManyToOne
Expanded class hierarchy of ManyToOne
2 files declare their use of ManyToOne
- ListField.php in core/
modules/ options/ src/ Plugin/ views/ filter/ ListField.php - TaxonomyIndexTid.php in core/
modules/ taxonomy/ src/ Plugin/ views/ filter/ TaxonomyIndexTid.php
File
- core/
modules/ views/ src/ Plugin/ views/ filter/ ManyToOne.php, line 23
Namespace
Drupal\views\Plugin\views\filterView source
class ManyToOne extends InOperator {
/**
* @var \Drupal\views\ManyToOneHelper
*
* Stores the Helper object which handles the many_to_one complexity.
*/
public $helper = NULL;
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->helper = new ManyToOneHelper($this);
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['operator']['default'] = 'or';
$options['value']['default'] = [];
if (isset($this->helper)) {
$this->helper
->defineOptions($options);
}
else {
$helper = new ManyToOneHelper($this);
$helper
->defineOptions($options);
}
return $options;
}
/**
* {@inheritdoc}
*/
public function operators() {
$operators = [
'or' => [
'title' => $this
->t('Is one of'),
'short' => $this
->t('or'),
'short_single' => $this
->t('='),
'method' => 'opHelper',
'values' => 1,
'ensure_my_table' => 'helper',
],
'and' => [
'title' => $this
->t('Is all of'),
'short' => $this
->t('and'),
'short_single' => $this
->t('='),
'method' => 'opHelper',
'values' => 1,
'ensure_my_table' => 'helper',
],
'not' => [
'title' => $this
->t('Is none of'),
'short' => $this
->t('not'),
'short_single' => $this
->t('<>'),
'method' => 'opHelper',
'values' => 1,
'ensure_my_table' => 'helper',
],
];
// if the definition allows for the empty operator, add it.
if (!empty($this->definition['allow empty'])) {
$operators += [
'empty' => [
'title' => $this
->t('Is empty (NULL)'),
'method' => 'opEmpty',
'short' => $this
->t('empty'),
'values' => 0,
],
'not empty' => [
'title' => $this
->t('Is not empty (NOT NULL)'),
'method' => 'opEmpty',
'short' => $this
->t('not empty'),
'values' => 0,
],
];
}
return $operators;
}
protected $valueFormType = 'select';
protected function valueForm(&$form, FormStateInterface $form_state) {
parent::valueForm($form, $form_state);
if (!$form_state
->get('exposed')) {
$this->helper
->buildOptionsForm($form, $form_state);
}
}
/**
* {@inheritdoc}
*/
public function ensureMyTable() {
// Defer to helper if the operator specifies it.
$info = $this
->operators();
if (isset($info[$this->operator]['ensure_my_table']) && $info[$this->operator]['ensure_my_table'] == 'helper') {
return $this->helper
->ensureMyTable();
}
return parent::ensureMyTable();
}
protected function opHelper() {
if (empty($this->value)) {
return;
}
// Form API returns unchecked options in the form of option_id => 0. This
// breaks the generated query for "is all of" filters so we remove them.
$this->value = array_filter($this->value, [
static::class,
'arrayFilterZero',
]);
$this->helper
->addFilter();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
InOperator:: |
protected | property | Stores all operations which are available on the form. | |
InOperator:: |
protected | property | The filter title. | |
InOperator:: |
public | function | 1 | |
InOperator:: |
public | function | 1 | |
InOperator:: |
public | function | 1 | |
InOperator:: |
public | function | ||
InOperator:: |
public | function | Gets the value options. | 6 |
InOperator:: |
protected | function | ||
InOperator:: |
public | function | Build strings from the operators() for 'select' options. | 1 |
InOperator:: |
protected | function | ||
InOperator:: |
protected | function | 1 | |
InOperator:: |
public | function | 2 | |
InOperator:: |
public | function | When using exposed filters, we may be required to reduce the set. | |
InOperator:: |
public | function | ||
InOperator:: |
protected | function | 1 | |
ManyToOne:: |
public | property | Stores the Helper object which handles the many_to_one complexity. | |
ManyToOne:: |
protected | property |
Overrides InOperator:: |
|
ManyToOne:: |
protected | function |
Overrides InOperator:: |
1 |
ManyToOne:: |
public | function | ||
ManyToOne:: |
public | function |
Overrides InOperator:: |
2 |
ManyToOne:: |
public | function |
Returns an array of operator information, keyed by operator ID. Overrides InOperator:: |
|
ManyToOne:: |
protected | function | ||
ManyToOne:: |
protected | function |
Overrides InOperator:: |
1 |