You are here

public function EntityQueuePosition::query in Entityqueue 8

Same name in this branch
  1. 8 src/Plugin/views/sort/EntityQueuePosition.php \Drupal\entityqueue\Plugin\views\sort\EntityQueuePosition::query()
  2. 8 src/Plugin/views/field/EntityQueuePosition.php \Drupal\entityqueue\Plugin\views\field\EntityQueuePosition::query()

.

Overrides FieldPluginBase::query

File

src/Plugin/views/field/EntityQueuePosition.php, line 71

Class

EntityQueuePosition
Field handler to display the position of an item in a queue.

Namespace

Drupal\entityqueue\Plugin\views\field

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) {

    // Add the field.
    $this->field_alias = $this->query
      ->addField($entity_queue_relationship->first_alias, $this->realField);
  }
  else {
    if ($this->currentUser
      ->hasPermission('administer views')) {
      $this->messenger
        ->addMessage($this
        ->t('In order to display the item position in 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);
    }
  }
}