NULL]; return $options; } /** * {@inheritdoc} */ public function buildOptionsForm(&$form, FormStateInterface $form_state) { $queues = EntityQueue::loadMultipleByTargetType($this->getEntityType()); $options = []; foreach ($queues as $queue) { $options[$queue->id()] = $queue->label(); } $form['limit_queue'] = [ '#type' => 'radios', '#title' => $this->t('Limit to a specific entity queue'), '#options' => $options, '#default_value' => $this->options['limit_queue'], ]; parent::buildOptionsForm($form, $form_state); } /** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); // Add an extra condition to limit results based on the queue selection. if ($this->options['limit_queue']) { $this->definition['extra'][] = [ 'field' => 'bundle', 'value' => $this->options['limit_queue'], ]; } } /** * {@inheritdoc} */ public function calculateDependencies() { $dependencies = parent::calculateDependencies(); if ($this->options['limit_queue']) { $queue = EntityQueue::load($this->options['limit_queue']); $dependencies[$queue->getConfigDependencyKey()][] = $queue->getConfigDependencyName(); } return $dependencies; } /** * {@inheritdoc} */ public function getCacheContexts() { return []; } /** * {@inheritdoc} */ public function getCacheTags() { $tags = []; if ($this->options['limit_queue']) { $queue = EntityQueue::load($this->options['limit_queue']); $tags = $queue->getCacheTags(); } return $tags; } /** * {@inheritdoc} */ public function getCacheMaxAge() { return Cache::PERMANENT; } /** * {@inheritdoc} */ public function query() { // Add a 'where' condition if needed. if (!empty($this->definition['extra'])) { $bundles = []; // Future-proofing: support any number of selected bundles. foreach ($this->definition['extra'] as $extra) { if ($extra['field'] == 'bundle') { $bundles[] = $extra['value']; } } if (count($bundles) > 0) { $this->definition['join_extra'][] = [ 'field' => 'bundle', 'value' => $bundles, ]; } } // Now - let's build the query. parent::query(); } }