EntityQueuePosition.php in Entityqueue 8
File
src/Plugin/views/field/EntityQueuePosition.php
View source
<?php
namespace Drupal\entityqueue\Plugin\views\field;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\entityqueue\Plugin\views\relationship\EntityQueueRelationship;
use Drupal\views\Plugin\views\field\NumericField;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityQueuePosition extends NumericField {
protected $currentUser;
protected $messenger;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, AccountInterface $current_user, MessengerInterface $messenger) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $current_user;
$this->messenger = $messenger;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'), $container
->get('messenger'));
}
public function query() {
$this
->ensureMyTable();
$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) {
$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);
}
}
}
}