class TestWebformHandler in Webform 6.x
Same name and namespace in other branches
- 8.5 tests/modules/webform_test_handler/src/Plugin/WebformHandler/TestWebformHandler.php \Drupal\webform_test_handler\Plugin\WebformHandler\TestWebformHandler
Webform submission test handler.
Plugin annotation
@WebformHandler(
id = "test",
label = @Translation("Test"),
category = @Translation("Testing"),
description = @Translation("Tests webform submission handler behaviors."),
cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_SINGLE,
results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_IGNORED,
submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_REQUIRED,
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\webform\Plugin\WebformHandlerBase implements WebformHandlerInterface uses WebformEntityStorageTrait, WebformEntityInjectionTrait, WebformPluginSettingsTrait
- class \Drupal\webform_test_handler\Plugin\WebformHandler\TestWebformHandler
- class \Drupal\webform\Plugin\WebformHandlerBase implements WebformHandlerInterface uses WebformEntityStorageTrait, WebformEntityInjectionTrait, WebformPluginSettingsTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TestWebformHandler
File
- tests/
modules/ webform_test_handler/ src/ Plugin/ WebformHandler/ TestWebformHandler.php, line 25
Namespace
Drupal\webform_test_handler\Plugin\WebformHandlerView source
class TestWebformHandler extends WebformHandlerBase {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'message' => 'One two one two this is just a test',
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['message'] = [
'#type' => 'textfield',
'#title' => $this
->t('Message'),
'#default_value' => $this->configuration['message'],
'#required' => TRUE,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['message'] = $form_state
->getValue('message');
}
/**
* {@inheritdoc}
*/
public function alterElements(array &$elements, WebformInterface $webform) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function alterElement(array &$element, FormStateInterface $form_state, array $context) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function overrideSettings(array &$settings, WebformSubmissionInterface $webform_submission) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function alterForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
$this
->displayMessage(__FUNCTION__);
$value = $form_state
->getValue('element');
if ($value && !in_array($value, [
'access_allowed',
'submission_access_denied',
'element_access_denied',
])) {
$form_state
->setErrorByName('element', $this
->t('The element must be empty. You entered %value.', [
'%value' => $value,
]));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function confirmForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
$this
->messenger()
->addStatus($this->configuration['message'], TRUE);
$this->loggerFactory
->get('webform.test_form')
->notice($this->configuration['message']);
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function preCreate(array &$values) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function postCreate(WebformSubmissionInterface $webform_submission) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function postLoad(WebformSubmissionInterface $webform_submission) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function preDelete(WebformSubmissionInterface $webform_submission) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function postDelete(WebformSubmissionInterface $webform_submission) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function preSave(WebformSubmissionInterface $webform_submission) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
$this
->displayMessage(__FUNCTION__, $update ? 'update' : 'insert');
}
/**
* {@inheritdoc}
*/
public function access(WebformSubmissionInterface $webform_submission, $operation, AccountInterface $account = NULL) {
$this
->displayMessage(__FUNCTION__ . 'Submission');
$value = $webform_submission
->getElementData('element');
if ($value === 'submission_access_denied') {
$access_result = AccessResult::forbidden();
}
else {
$access_result = parent::access($webform_submission, $operation, $account);
}
return $access_result
->setCacheMaxAge(0);
}
/**
* {@inheritdoc}
*/
public function preprocessConfirmation(array &$variables) {
$this
->displayMessage(__FUNCTION__);
$variables['message'] = '::preprocessConfirmation';
}
/**
* {@inheritdoc}
*/
public function createHandler() {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function updateHandler() {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function deleteHandler() {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function accessElement(array &$element, $operation, AccountInterface $account = NULL) {
$this
->displayMessage(__FUNCTION__);
$webform_submission = $this
->getWebformSubmission();
if ($webform_submission && $webform_submission
->getElementData('element') === 'element_access_denied') {
$access_result = AccessResult::forbidden();
}
else {
$access_result = parent::accessElement($element, $operation, $account);
}
return $access_result
->setCacheMaxAge(0);
}
/**
* {@inheritdoc}
*/
public function createElement($key, array $element) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function updateElement($key, array $element, array $original_element) {
$this
->displayMessage(__FUNCTION__);
}
/**
* {@inheritdoc}
*/
public function deleteElement($key, array $element) {
$this
->displayMessage(__FUNCTION__);
}
/**
* Display the invoked plugin method to end user.
*
* @param string $method_name
* The invoked method name.
* @param string $context1
* Additional parameter passed to the invoked method name.
*/
protected function displayMessage($method_name, $context1 = NULL) {
if (PHP_SAPI !== 'cli') {
$t_args = [
'@id' => $this
->getHandlerId(),
'@class_name' => get_class($this),
'@method_name' => $method_name,
'@context1' => $context1,
];
$this
->messenger()
->addStatus($this
->t('Invoked @id: @class_name:@method_name @context1', $t_args), TRUE);
$this->loggerFactory
->get('webform.test_form')
->notice('Invoked: @class_name:@method_name @context1', $t_args);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 98 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TestWebformHandler:: |
public | function |
Controls entity operation access to webform submission. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Controls entity operation access to webform submission element. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Alter webform element. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Alter webform submission webform elements. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Alter webform submission form. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Form constructor. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Confirm webform submission form. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on a element after it has been created. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on handler after it has been created and added to webform. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Gets default configuration for this plugin. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on a element after it has been deleted. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on handler after it has been removed. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
protected | function | Display the invoked plugin method to end user. | |
TestWebformHandler:: |
public | function |
Alter/override a webform submission webform settings. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on a webform submission after it is created. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on deleted a webform submission before the delete hook is invoked. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on loaded webform submission. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on a saved webform submission before the insert or update hook is invoked. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Changes the values of an entity before it is created. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on a webform submission before they are deleted and before hooks are invoked. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Prepares variables for webform confirmation templates. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on a webform submission before the presave hook is invoked. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Form submission handler. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Submit webform submission form. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on a element after it has been updated. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Acts on handler after it has been updated. Overrides WebformHandlerBase:: |
|
TestWebformHandler:: |
public | function |
Validate webform submission form. Overrides WebformHandlerBase:: |
|
WebformEntityInjectionTrait:: |
public | function | Get the webform that this handler is attached to. | |
WebformEntityInjectionTrait:: |
public | function | Set webform and webform submission entity. | |
WebformEntityInjectionTrait:: |
public | function | Reset webform and webform submission entity. | |
WebformEntityInjectionTrait:: |
public | function | ||
WebformEntityInjectionTrait:: |
public | function | Set the webform that this is handler is attached to. | |
WebformEntityInjectionTrait:: |
public | function | Get the webform submission that this handler is handling. | |
WebformEntityStorageTrait:: |
protected | property | An associate array of entity type storage aliases. | |
WebformEntityStorageTrait:: |
protected | property | The entity type manager. | 5 |
WebformEntityStorageTrait:: |
protected | function | Retrieves the entity storage. | |
WebformEntityStorageTrait:: |
protected | function | Retrieves the webform submission storage. | |
WebformEntityStorageTrait:: |
protected | function | Retrieves the webform storage. | |
WebformEntityStorageTrait:: |
public | function | Implements the magic __get() method. | |
WebformHandlerBase:: |
protected | property | The webform handler's conditions. | |
WebformHandlerBase:: |
protected | property | The webform handler's conditions result cache. | |
WebformHandlerBase:: |
protected | property | The webform submission (server-side) conditions (#states) validator. | |
WebformHandlerBase:: |
protected | property | The configuration factory. | 1 |
WebformHandlerBase:: |
protected | property | The webform handler ID. | |
WebformHandlerBase:: |
protected | property | The webform handler label. | |
WebformHandlerBase:: |
protected | property | The logger factory. | |
WebformHandlerBase:: |
protected | property | The webform variant notes. | |
WebformHandlerBase:: |
protected | property | The renderer. | 1 |
WebformHandlerBase:: |
protected | property | The webform handler status. | |
WebformHandlerBase:: |
protected | property | The webform token manager. | 6 |
WebformHandlerBase:: |
protected | property |
The webform. Overrides WebformEntityInjectionTrait:: |
|
WebformHandlerBase:: |
protected | property |
The webform submission. Overrides WebformEntityInjectionTrait:: |
|
WebformHandlerBase:: |
protected | property | The weight of the webform handler. | |
WebformHandlerBase:: |
protected | function | Apply submitted form state to configuration. | |
WebformHandlerBase:: |
protected | function | Build token tree element. | 2 |
WebformHandlerBase:: |
public | function |
Returns the webform handler cardinality settings. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Check handler conditions against a webform submission. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public static | function |
IMPORTANT:
Webform handlers are initialized and serialized when they are attached to a
webform. Make sure not include any services as a dependency injection
that directly connect to the database. This will prevent
"LogicException: The database… Overrides ContainerFactoryPluginInterface:: |
8 |
WebformHandlerBase:: |
public | function |
Returns the webform handler description. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Disables the webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
protected | function | Validate form that should have tokens in it. | |
WebformHandlerBase:: |
public | function |
Enables the webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Returns the conditions the webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
WebformHandlerBase:: |
public | function |
Returns the unique ID representing the webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Returns the label of the webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
protected | function | Get webform or webform_submission logger. | |
WebformHandlerBase:: |
public | function |
Returns notes of the webform variant. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Get configuration form's off-canvas width. Overrides WebformHandlerInterface:: |
1 |
WebformHandlerBase:: |
public | function |
Returns the status of the webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Returns a render array summarizing the configuration of the webform handler. Overrides WebformHandlerInterface:: |
8 |
WebformHandlerBase:: |
public | function |
Returns the weight of the webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Determine if the webform handler requires anonymous submission tracking. Overrides WebformHandlerInterface:: |
1 |
WebformHandlerBase:: |
public | function |
Determine if this handle is applicable to the webform. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Returns the webform handler disabled indicator. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Returns the webform handler enabled indicator. Overrides WebformHandlerInterface:: |
1 |
WebformHandlerBase:: |
public | function |
Checks if the handler is excluded via webform.settings. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Returns the webform submission is optional indicator. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Returns the webform submission is required indicator. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Returns the webform handler label. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Acts on webform submissions after they are purged. Overrides WebformHandlerInterface:: |
1 |
WebformHandlerBase:: |
public | function |
Acts on an webform submission about to be shown on a webform submission form. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Acts on webform submissions before they are purged. Overrides WebformHandlerInterface:: |
1 |
WebformHandlerBase:: |
protected | function | Replace tokens in text with no render context. | |
WebformHandlerBase:: |
public | function |
Sets the conditions for this webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
WebformHandlerBase:: |
public | function |
Sets the id for this webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Sets the label for this webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Set notes for this webform variant. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
protected | function | Set configuration settings parents. | |
WebformHandlerBase:: |
protected | function | Set configuration settings parents. | |
WebformHandlerBase:: |
public | function |
Sets the status for this webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Sets the weight for this webform handler. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Determine if webform handler supports conditions. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Determine if webform handler supports tokens. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
3 |
WebformHandlerInterface:: |
constant | Value indicating a single plugin instances are permitted. | ||
WebformHandlerInterface:: |
constant | Value indicating unlimited plugin instances are permitted. | ||
WebformHandlerInterface:: |
constant | Value indicating webform submissions are not processed (i.e. email or saved) by the handler. | ||
WebformHandlerInterface:: |
constant | Value indicating webform submissions are processed (i.e. email or saved) by the handler. | ||
WebformHandlerInterface:: |
constant | Value indicating webform submissions do not have to be stored in the database. | ||
WebformHandlerInterface:: |
constant | Value indicating webform submissions must be stored in the database. | ||
WebformPluginSettingsTrait:: |
public | function | ||
WebformPluginSettingsTrait:: |
public | function | ||
WebformPluginSettingsTrait:: |
public | function | ||
WebformPluginSettingsTrait:: |
public | function |