You are here

public function EntityQueueInQueue::query in Entityqueue 8

Same name in this branch
  1. 8 src/Plugin/views/filter/EntityQueueInQueue.php \Drupal\entityqueue\Plugin\views\filter\EntityQueueInQueue::query()
  2. 8 src/Plugin/views/sort/EntityQueueInQueue.php \Drupal\entityqueue\Plugin\views\sort\EntityQueueInQueue::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 BooleanOperator::query

File

src/Plugin/views/filter/EntityQueueInQueue.php, line 71

Class

EntityQueueInQueue
Filter for entities that are available or not in an entity queue.

Namespace

Drupal\entityqueue\Plugin\views\filter

Code

public function query() {
  $this
    ->ensureMyTable();

  // Try to find an entity queue relationship in this view, and pick the first
  // one available.
  $entity_queue_relationship = NULL;
  foreach ($this->view->relationship as $id => $relationship) {
    if ($relationship instanceof EntityQueueRelationship) {
      $entity_queue_relationship = $relationship;
      $this->options['relationship'] = $id;
      $this
        ->setRelationship();
      break;
    }
  }
  if ($entity_queue_relationship) {
    $subqueue_items_table_alias = $entity_queue_relationship->first_alias;
    $field_field = $this->definition['field field'];
    $operator = $this->value ? 'IS NOT NULL' : 'IS NULL';
    $condition = "{$subqueue_items_table_alias}.{$field_field} {$operator}";
    $this->query
      ->addWhereExpression($this->options['group'], $condition);
  }
  else {
    if ($this->currentUser
      ->hasPermission('administer views')) {
      $this->messenger
        ->addMessage($this
        ->t('In order to filter on items from the queue, you need to add an <em>Entityqueue</em> relationship on the %display display of the %view view.', [
        '%view' => $this->view->storage
          ->label(),
        '%display' => $this->view->current_display,
      ]), MessengerInterface::TYPE_ERROR);
    }
  }
}