3 namespace Drupal\entityqueue\Plugin\views\filter;
5 use Drupal\Core\Session\AccountInterface;
6 use Drupal\entityqueue\Plugin\views\relationship\EntityQueueRelationship;
7 use Drupal\views\Plugin\views\filter\BooleanOperator;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Filter for entities that are available or not in an entity queue.
13 * @ingroup views_filter_handlers
15 * @ViewsFilter("entity_queue_in_queue")
17 class EntityQueueInQueue extends BooleanOperator {
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) {
76 $subqueue_items_table_alias = $entity_queue_relationship->first_alias;
77 $field_field = $this->definition['field field'];
78 $operator = $this->value ? 'IS NOT NULL' : 'IS NULL';
79 $condition = "$subqueue_items_table_alias.$field_field $operator";
81 $this->query->addWhereExpression($this->options['group'], $condition);
84 if ($this->currentUser->hasPermission('administer views')) {
85 drupal_set_message($this->t('In order to filter on items from the queue, 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');