You are here

public function MediaDirectoryArgument::query in Media Directories 8

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

Set up the query for this argument.

The argument sent may be found at $this->argument.

Overrides ArgumentPluginBase::query

File

src/Plugin/views/argument/MediaDirectoryArgument.php, line 108

Class

MediaDirectoryArgument
Media directory argument plugin.

Namespace

Drupal\media_directories\Plugin\views\argument

Code

public function query($group_by = FALSE) {
  $this
    ->ensureMyTable();
  $config = $this->configFactory
    ->get('media_directories.settings');
  $placeholder = $this
    ->placeholder();
  $null_check = empty($this->options['not']) ? '' : " OR {$this->tableAlias}.{$this->realField} IS NULL";
  if ((int) $this->argument === MEDIA_DIRECTORY_ROOT) {
    $group = 0;
    if ($config
      ->get('all_files_in_root')) {

      // We want an exclusive group if we change to OR.
      $group = 9;

      // Show everything.
      $this->query
        ->setWhereGroup('OR', $group);
      $this->query
        ->addWhereExpression($group, "{$this->tableAlias}.{$this->realField} IS NOT NULL");
    }
    $this->query
      ->addWhereExpression($group, "{$this->tableAlias}.{$this->realField} IS NULL");
  }
  else {
    $operator = empty($this->options['not']) ? '=' : '!=';
    $this->query
      ->addWhereExpression(0, "{$this->tableAlias}.{$this->realField} {$operator} {$placeholder}" . $null_check, [
      $placeholder => $this->argument,
    ]);
  }
}