WebformSubmissionSelectFilter.php in Webform Views Integration 8.5
File
src/Plugin/views/filter/WebformSubmissionSelectFilter.php
View source
<?php
namespace Drupal\webform_views\Plugin\views\filter;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\InOperator;
use Drupal\webform_views\Plugin\views\WebformSubmissionTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformSubmissionSelectFilter extends InOperator {
use WebformSubmissionTrait;
const ALL = 'all';
protected $valueFormType = 'select';
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 __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
protected function valueForm(&$form, FormStateInterface $form_state) {
parent::valueForm($form, $form_state);
$form['value']['#required'] = FALSE;
unset($form['value']['#options'][self::ALL]);
}
public function showValueForm(&$form, FormStateInterface $form_state) {
parent::showValueForm($form, $form_state);
$form['value']['#options'] = [
self::ALL => $this->valueOptions[self::ALL],
] + $form['value']['#options'];
}
public function getValueOptions() {
if (!isset($this->valueOptions)) {
$element = $this
->getWebformElement();
$this->valueOptions = [
self::ALL => $this
->t('All'),
];
$this->valueOptions += $element['#options'];
}
return $this->valueOptions;
}
public function acceptExposedInput($input) {
$accept = parent::acceptExposedInput($input);
$identifier = $this->options['expose']['identifier'];
if ($input[$identifier] == self::ALL) {
return FALSE;
}
return $accept;
}
}