You are here

public function ManyToOne::operators in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/filter/ManyToOne.php \Drupal\views\Plugin\views\filter\ManyToOne::operators()
  2. 9 core/modules/views/src/Plugin/views/filter/ManyToOne.php \Drupal\views\Plugin\views\filter\ManyToOne::operators()

This kind of construct makes it relatively easy for a child class to add or remove functionality by overriding this function and adding/removing items from this array.

Overrides InOperator::operators

2 calls to ManyToOne::operators()
ManyToOne::ensureMyTable in core/modules/views/src/Plugin/views/filter/ManyToOne.php
Override ensureMyTable so we can control how this joins in. The operator actually has influence over joining.
Roles::operators in core/modules/user/src/Plugin/views/filter/Roles.php
Override empty and not empty operator labels to be clearer for user roles.
1 method overrides ManyToOne::operators()
Roles::operators in core/modules/user/src/Plugin/views/filter/Roles.php
Override empty and not empty operator labels to be clearer for user roles.

File

core/modules/views/src/Plugin/views/filter/ManyToOne.php, line 57

Class

ManyToOne
Complex filter to handle filtering for many to one relationships, such as terms (many terms per node) or roles (many roles per user).

Namespace

Drupal\views\Plugin\views\filter

Code

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;
}