You are here

public function StringEntity::operators in Configuration Views 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/views/filter/StringEntity.php \Drupal\config_views\Plugin\views\filter\StringEntity::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 StringFilter::operators

1 call to StringEntity::operators()
StringEntity::query in src/Plugin/views/filter/StringEntity.php
Add this filter to the query.

File

src/Plugin/views/filter/StringEntity.php, line 24

Class

StringEntity
Views filter for strings to work with config entities.

Namespace

Drupal\config_views\Plugin\views\filter

Code

public function operators() {
  $operators = [
    '=' => [
      'title' => $this
        ->t('Is equal to'),
      'short' => $this
        ->t('='),
      'method' => 'opSimple',
      'values' => 1,
    ],
    '<>' => [
      'title' => $this
        ->t('Is not equal to'),
      'short' => $this
        ->t('<>'),
      'method' => 'opSimple',
      'values' => 1,
    ],
    'CONTAINS' => [
      'title' => $this
        ->t('Contains'),
      'short' => $this
        ->t('contains'),
      'method' => 'opSimple',
      'values' => 1,
    ],
    'STARTS_WITH' => [
      'title' => $this
        ->t('Starts with'),
      'short' => $this
        ->t('begins'),
      'method' => 'opSimple',
      'values' => 1,
    ],
    'ENDS_WITH' => [
      'title' => $this
        ->t('Ends with'),
      'short' => $this
        ->t('ends'),
      'method' => 'opSimple',
      'values' => 1,
    ],
  ];

  // If the definition allows for the empty operator, add it.
  if (!empty($this->definition['allow empty'])) {
    $operators += [
      'IS NULL' => [
        'title' => $this
          ->t('Is empty (NULL)'),
        'method' => 'opEmpty',
        'short' => $this
          ->t('empty'),
        'values' => 0,
      ],
      'IS NOT NULL' => [
        'title' => $this
          ->t('Is not empty (NOT NULL)'),
        'method' => 'opNotEmpty',
        'short' => $this
          ->t('not empty'),
        'values' => 0,
      ],
    ];
  }
  return $operators;
}