You are here

public function MediaDirectory::query in Media Directories 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/views/filter/MediaDirectory.php \Drupal\media_directories\Plugin\views\filter\MediaDirectory::query()
  2. 3.x src/Plugin/views/filter/MediaDirectory.php \Drupal\media_directories\Plugin\views\filter\MediaDirectory::query()

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides InOperator::query

File

src/Plugin/views/filter/MediaDirectory.php, line 207

Class

MediaDirectory
Filter media by directory.

Namespace

Drupal\media_directories\Plugin\views\filter

Code

public function query() {
  $this
    ->ensureMyTable();
  $config = $this->configFactory
    ->get('media_directories.settings');

  // If the value is 'All', then we show only elements with empty value.
  if ($this->validatedExposedInput[0] === 'All') {
    $new_group = $this->query
      ->setWhereGroup('AND');
    $this->query
      ->addWhereExpression($new_group, "{$this->tableAlias}.{$this->realField} IS NULL");
    if ($config
      ->get('all_files_in_root')) {

      // Show everything.
      $this->query
        ->setWhereGroup('OR', $new_group);
      $this->query
        ->addWhereExpression($new_group, "{$this->tableAlias}.{$this->realField} IS NOT NULL");
    }
  }
  else {
    parent::query();
  }
}