TestWebformHandler.php in Webform Encrypt 8
File
tests/modules/webform_encrypt_test/src/Plugin/WebformHandler/TestWebformHandler.php
View source
<?php
namespace Drupal\webform_encrypt_test\Plugin\WebformHandler;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\State\StateInterface;
use Drupal\webform\Plugin\WebformHandlerBase;
use Drupal\webform\WebformSubmissionConditionsValidatorInterface;
use Drupal\webform\WebformSubmissionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TestWebformHandler extends WebformHandlerBase {
protected $state;
public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformSubmissionConditionsValidatorInterface $conditions_validator, StateInterface $state) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $logger_factory, $config_factory, $entity_type_manager, $conditions_validator);
$this->state = $state;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('logger.factory'), $container
->get('config.factory'), $container
->get('entity_type.manager'), $container
->get('webform_submission.conditions_validator'), $container
->get('state'));
}
public function preSave(WebformSubmissionInterface $webform_submission) {
$counter = $this->state
->get('test_webform_handler_presave_counter', 0);
$this->state
->set('test_webform_handler_presave_counter', ++$counter);
}
}