You are here

function StringFilter::operators in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 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 38
Contains \Drupal\views\Plugin\views\filter\StringFilter.

Class

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

Namespace

Drupal\views\Plugin\views\filter

Code

function operators() {
  $operators = array(
    '=' => array(
      'title' => $this
        ->t('Is equal to'),
      'short' => $this
        ->t('='),
      'method' => 'opEqual',
      'values' => 1,
    ),
    '!=' => array(
      'title' => $this
        ->t('Is not equal to'),
      'short' => $this
        ->t('!='),
      'method' => 'opEqual',
      'values' => 1,
    ),
    'contains' => array(
      'title' => $this
        ->t('Contains'),
      'short' => $this
        ->t('contains'),
      'method' => 'opContains',
      'values' => 1,
    ),
    'word' => array(
      'title' => $this
        ->t('Contains any word'),
      'short' => $this
        ->t('has word'),
      'method' => 'opContainsWord',
      'values' => 1,
    ),
    'allwords' => array(
      'title' => $this
        ->t('Contains all words'),
      'short' => $this
        ->t('has all'),
      'method' => 'opContainsWord',
      'values' => 1,
    ),
    'starts' => array(
      'title' => $this
        ->t('Starts with'),
      'short' => $this
        ->t('begins'),
      'method' => 'opStartsWith',
      'values' => 1,
    ),
    'not_starts' => array(
      'title' => $this
        ->t('Does not start with'),
      'short' => $this
        ->t('not_begins'),
      'method' => 'opNotStartsWith',
      'values' => 1,
    ),
    'ends' => array(
      'title' => $this
        ->t('Ends with'),
      'short' => $this
        ->t('ends'),
      'method' => 'opEndsWith',
      'values' => 1,
    ),
    'not_ends' => array(
      'title' => $this
        ->t('Does not end with'),
      'short' => $this
        ->t('not_ends'),
      'method' => 'opNotEndsWith',
      'values' => 1,
    ),
    'not' => array(
      'title' => $this
        ->t('Does not contain'),
      'short' => $this
        ->t('!has'),
      'method' => 'opNotLike',
      'values' => 1,
    ),
    'shorterthan' => array(
      'title' => $this
        ->t('Length is shorter than'),
      'short' => $this
        ->t('shorter than'),
      'method' => 'opShorterThan',
      'values' => 1,
    ),
    'longerthan' => array(
      'title' => $this
        ->t('Length is longer than'),
      'short' => $this
        ->t('longer than'),
      'method' => 'opLongerThan',
      'values' => 1,
    ),
    'regular_expression' => array(
      '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 += array(
      'empty' => array(
        'title' => $this
          ->t('Is empty (NULL)'),
        'method' => 'opEmpty',
        'short' => $this
          ->t('empty'),
        'values' => 0,
      ),
      'not empty' => array(
        'title' => $this
          ->t('Is not empty (NOT NULL)'),
        'method' => 'opEmpty',
        'short' => $this
          ->t('not empty'),
        'values' => 0,
      ),
    );
  }
  return $operators;
}