You are here

public function StringFilter::operators in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/StringFilter.php \Drupal\views\Plugin\views\filter\StringFilter::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.

4 calls to StringFilter::operators()
Combine::query in core/modules/views/src/Plugin/views/filter/Combine.php
Add this filter to the query.
StringFilter::operatorOptions in core/modules/views/src/Plugin/views/filter/StringFilter.php
Build strings from the operators() for 'select' options
StringFilter::operatorValues in core/modules/views/src/Plugin/views/filter/StringFilter.php
StringFilter::query in core/modules/views/src/Plugin/views/filter/StringFilter.php
Add this filter to the query.

File

core/modules/views/src/Plugin/views/filter/StringFilter.php, line 100

Class

StringFilter
Basic textfield filter to handle string filtering commands including equality, like, not like, etc.

Namespace

Drupal\views\Plugin\views\filter

Code

public function operators() {
  $operators = [
    '=' => [
      'title' => $this
        ->t('Is equal to'),
      'short' => $this
        ->t('='),
      'method' => 'opEqual',
      'values' => 1,
    ],
    '!=' => [
      'title' => $this
        ->t('Is not equal to'),
      'short' => $this
        ->t('!='),
      'method' => 'opEqual',
      'values' => 1,
    ],
    'contains' => [
      'title' => $this
        ->t('Contains'),
      'short' => $this
        ->t('contains'),
      'method' => 'opContains',
      'values' => 1,
    ],
    'word' => [
      'title' => $this
        ->t('Contains any word'),
      'short' => $this
        ->t('has word'),
      'method' => 'opContainsWord',
      'values' => 1,
    ],
    'allwords' => [
      'title' => $this
        ->t('Contains all words'),
      'short' => $this
        ->t('has all'),
      'method' => 'opContainsWord',
      'values' => 1,
    ],
    'starts' => [
      'title' => $this
        ->t('Starts with'),
      'short' => $this
        ->t('begins'),
      'method' => 'opStartsWith',
      'values' => 1,
    ],
    'not_starts' => [
      'title' => $this
        ->t('Does not start with'),
      'short' => $this
        ->t('not_begins'),
      'method' => 'opNotStartsWith',
      'values' => 1,
    ],
    'ends' => [
      'title' => $this
        ->t('Ends with'),
      'short' => $this
        ->t('ends'),
      'method' => 'opEndsWith',
      'values' => 1,
    ],
    'not_ends' => [
      'title' => $this
        ->t('Does not end with'),
      'short' => $this
        ->t('not_ends'),
      'method' => 'opNotEndsWith',
      'values' => 1,
    ],
    'not' => [
      'title' => $this
        ->t('Does not contain'),
      'short' => $this
        ->t('!has'),
      'method' => 'opNotLike',
      'values' => 1,
    ],
    'shorterthan' => [
      'title' => $this
        ->t('Length is shorter than'),
      'short' => $this
        ->t('shorter than'),
      'method' => 'opShorterThan',
      'values' => 1,
    ],
    'longerthan' => [
      'title' => $this
        ->t('Length is longer than'),
      'short' => $this
        ->t('longer than'),
      'method' => 'opLongerThan',
      'values' => 1,
    ],
    'regular_expression' => [
      'title' => $this
        ->t('Regular expression'),
      'short' => $this
        ->t('regex'),
      'method' => 'opRegex',
      'values' => 1,
    ],
  ];

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