WebformSubmissionWebformCategory.php in Webform Views Integration 8.5
File
src/Plugin/views/filter/WebformSubmissionWebformCategory.php
View source
<?php
namespace Drupal\webform_views\Plugin\views\filter;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\views\Plugin\views\filter\StringFilter;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformSubmissionWebformCategory extends StringFilter {
protected $entityTypeManager;
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance
->setEntityTypeManager($container
->get('entity_type.manager'));
return $instance;
}
public function operators() {
$operators = parent::operators();
unset($operators['word']);
unset($operators['allwords']);
unset($operators['not_starts']);
unset($operators['not_ends']);
unset($operators['not']);
unset($operators['shorterthan']);
unset($operators['longerthan']);
unset($operators['regular_expression']);
$operators['=']['webform_operator'] = '=';
$operators['!=']['webform_operator'] = '<>';
$operators['contains']['webform_operator'] = 'CONTAINS';
$operators['starts']['webform_operator'] = 'STARTS_WITH';
$operators['ends']['webform_operator'] = 'ENDS_WITH';
return $operators;
}
public function query() {
$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');
}
}
public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
protected function getApplicableWebformIds() {
$operator = $this
->operators()[$this->operator];
$query = $this->entityTypeManager
->getStorage('webform')
->getQuery();
$query
->condition('category', $this->value, $operator['webform_operator']);
return array_values($query
->execute());
}
}