EntityQueueSmartQueueArgument.php in Entityqueue 8
File
modules/entityqueue_smartqueue/src/Plugin/views/argument/EntityQueueSmartQueueArgument.php
View source
<?php
namespace Drupal\entityqueue_smartqueue\Plugin\views\argument;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\argument\StringArgument;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityQueueSmartQueueArgument extends StringArgument {
protected $entityTypeManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
}
public function defineOptions() {
$options = parent::defineOptions();
$options['smartqueue'] = [
'default' => NULL,
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$smartqueues = $this->entityTypeManager
->getStorage('entity_queue')
->loadByProperties([
'handler' => 'smartqueue',
]);
$options = [];
foreach ($smartqueues as $queue) {
$options[$queue
->id()] = $queue
->label();
}
$form['smartqueue'] = [
'#type' => 'select',
'#title' => $this
->t('Smartqueue ID'),
'#default_value' => $this->options['smartqueue'],
'#options' => $options,
];
}
public function setArgument($arg) {
$queue = $this->options['smartqueue'];
if (strpos($arg, $queue) !== 0) {
$arg = $queue . '__' . $arg;
}
return parent::setArgument($arg);
}
}