3 namespace Drupal\entityqueue\Plugin\views\sort;
5 use Drupal\Core\Session\AccountInterface;
6 use Drupal\entityqueue\Plugin\views\relationship\EntityQueueRelationship;
7 use Drupal\views\Plugin\views\sort\SortPluginBase;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Default implementation of the base sort plugin.
13 * @ingroup views_sort_handlers
15 * @ViewsSort("entity_queue_position")
17 class EntityQueuePosition extends SortPluginBase {
22 * @var \Drupal\Core\Session\AccountInterface
24 protected $currentUser;
29 * @param array $configuration
30 * A configuration array containing information about the plugin instance.
31 * @param string $plugin_id
32 * The plugin_id for the plugin instance.
33 * @param array $plugin_definition
34 * The plugin implementation definition.
35 * @param \Drupal\Core\Session\AccountInterface $current_user
38 public function __construct(array $configuration, $plugin_id, array $plugin_definition, AccountInterface $current_user) {
39 parent::__construct($configuration, $plugin_id, $plugin_definition);
41 $this->currentUser = $current_user;
47 public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
52 $container->get('current_user')
59 public function query() {
60 $this->ensureMyTable();
62 // Try to find an entity queue relationship in this view, and pick the first
64 $entity_queue_relationship = NULL;
65 foreach ($this->view->relationship as $id => $relationship) {
66 if ($relationship instanceof EntityQueueRelationship) {
67 $entity_queue_relationship = $relationship;
68 $this->options['relationship'] = $id;
69 $this->setRelationship();
75 if ($entity_queue_relationship) {
77 $subqueue_items_table_alias = $entity_queue_relationship->first_alias;
78 $this->query->addOrderBy($subqueue_items_table_alias, $this->realField, $this->options['order']);
81 if ($this->currentUser->hasPermission('administer views')) {
82 drupal_set_message($this->t('In order to sort by the queue position, you need to add the Entityqueue: Queue relationship on View: @view with display: @display', ['@view' => $this->view->storage->label(), '@display' => $this->view->current_display]), 'error');