WebformSubmissionWebformStatus.php in Webform Views Integration 8.5
File
src/Plugin/views/filter/WebformSubmissionWebformStatus.php
View source
<?php
namespace Drupal\webform_views\Plugin\views\filter;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\filter\InOperator;
use Drupal\views\ViewExecutable;
use Drupal\webform\WebformInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformSubmissionWebformStatus extends InOperator {
protected $entityTypeManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->valueOptions = [
WebformInterface::STATUS_OPEN => $this
->t('Open'),
WebformInterface::STATUS_CLOSED => $this
->t('Closed'),
WebformInterface::STATUS_SCHEDULED => $this
->t('Scheduled'),
];
}
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 operators() {
$operators = parent::operators();
$operators['in']['webform_operator'] = 'IN';
$operators['not in']['webform_operator'] = 'NOT IN';
return $operators;
}
protected function opSimple() {
$webform_ids = $this
->getApplicableWebformIds();
if (empty($webform_ids)) {
$this->query
->addWhereExpression($this->options['group'], '1 = 0');
}
else {
$this
->ensureMyTable();
$this->query
->addWhere($this->options['group'], "{$this->tableAlias}.{$this->realField}", $webform_ids, 'IN');
}
}
protected function getApplicableWebformIds() {
$operator = $this
->operators()[$this->operator];
$query = $this->entityTypeManager
->getStorage('webform')
->getQuery();
$query
->condition('status', $this->value, $operator['webform_operator']);
return array_values($query
->execute());
}
}