class MaestroWebformHandler in Maestro 3.x
Same name and namespace in other branches
- 8.2 modules/maestro_webform/src/Plugin/WebformHandler/MaestroWebformHandler.php \Drupal\maestro_webform\Plugin\WebformHandler\MaestroWebformHandler
Launches a Maestro workflow with a Webform submission.
Plugin annotation
@WebformHandler(
id = "maestro",
label = @Translation("Spawn Maestro Workflow"),
category = @Translation("Workflow"),
description = @Translation("Spawns a Maestro Workflow and passes the newly created webform to the process."),
cardinality = \Drupal\webform\Plugin\WebformHandlerInterface::CARDINALITY_UNLIMITED,
results = \Drupal\webform\Plugin\WebformHandlerInterface::RESULTS_PROCESSED,
submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_OPTIONAL,
)
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\maestro_webform\Plugin\WebformHandler\MaestroWebformHandler
- class \Drupal\webform\Plugin\WebformHandlerBase implements WebformHandlerInterface uses WebformEntityStorageTrait, WebformEntityInjectionTrait, WebformPluginSettingsTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of MaestroWebformHandler
File
- modules/
maestro_webform/ src/ Plugin/ WebformHandler/ MaestroWebformHandler.php, line 30
Namespace
Drupal\maestro_webform\Plugin\WebformHandlerView source
class MaestroWebformHandler extends WebformHandlerBase {
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* The language manager.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* The configuration object factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* A mail manager for sending email.
*
* @var \Drupal\Core\Mail\MailManagerInterface
*/
protected $mailManager;
/**
* The webform token manager.
*
* @var \Drupal\webform\WebformTokenManagerInterface
*/
protected $tokenManager;
/**
* The webform theme manager.
*
* @var \Drupal\webform\WebformThemeManagerInterface
*/
protected $themeManager;
/**
* The webform element plugin manager.
*
* @var \Drupal\webform\Plugin\WebformElementManagerInterface
*/
protected $elementManager;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->currentUser = $container
->get('current_user');
$instance->moduleHandler = $container
->get('module_handler');
$instance->languageManager = $container
->get('language_manager');
$instance->mailManager = $container
->get('plugin.manager.mail');
$instance->themeManager = $container
->get('webform.theme_manager');
$instance->tokenManager = $container
->get('webform.token_manager');
$instance->elementManager = $container
->get('plugin.manager.webform.element');
return $instance;
}
/**
* {@inheritdoc}
*/
public function getSummary() {
// Gets the overall settings.
$summary = parent::getSummary();
// Lets now fetch the Maestro Template label.
$template = MaestroEngine::getTemplate($this->configuration['maestro_template']);
$summary['#settings']['template_label'] = $template->label;
return $summary;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'maestro_template' => '',
'maestro_message_success' => '',
'maestro_message_failure' => '',
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$maestro_templates = MaestroEngine::getTemplates();
$templates = [];
$templates['none'] = $this
->t('Select Template');
foreach ($maestro_templates as $machine_name => $template) {
$templates[$machine_name] = $template->label;
}
$form['maestro_template'] = [
'#type' => 'select',
'#title' => $this
->t('Maestro Workflow Template'),
'#description' => $this
->t('The template you choose will be spawned when the webform submission occurs.'),
'#default_value' => $this->configuration['maestro_template'],
'#options' => $templates,
'#suffix' => $this
->t('Maestro will use a default unique_identifier called "submission" to track this content in the launched workflow.
Only <b>VALIDATED</b> templates will be spawned.'),
];
$form['maestro_message_success'] = [
'#type' => 'textfield',
'#title' => $this
->t('Message to user on submission'),
'#description' => $this
->t('When a user submits the webform, what message would you like to show the user (Uses a Drupal message). Leave blank for no message.'),
'#default_value' => $this->configuration['maestro_message_success'],
];
$form['maestro_message_failure'] = [
'#type' => 'textfield',
'#title' => $this
->t('Message to user when a Maestro process fails to start.'),
'#description' => $this
->t('If a Maestro Process fails to start, this message will be displayed to the end user (Uses a Drupal message). Leave blank for no message.'),
'#default_value' => $this->configuration['maestro_message_failure'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$values = $form_state
->getValues();
foreach ($this->configuration as $name => $value) {
if (isset($values[$name])) {
$this->configuration[$name] = $values[$name];
}
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state, WebformSubmissionInterface $webform_submission) {
// If we have maestro elements in the URL, we know that this is a submission that is as a result of
// the task being INSIDE of a workflow and not spawned by itself.
// If we can bind to a template task based on the maestro elements, then we will
// set a webform submission data value signalling NOT to do any post-save actions if the task
// has it's webform submission handler option checked off.
// Make sure the key exists and default to not checked.
$webform_submission->data['maestro_skip'] = FALSE;
$maestroElements = $form_state
->getValue('maestro');
if ($maestroElements) {
$queueID = $maestroElements['queue_id'];
$templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
if ($templateTask) {
// $webform_submission->setElementData('maestro_skip', $templateTask['data']['skip_webform_handlers']);
$webform_submission->data['maestro_skip'] = $templateTask['data']['skip_webform_handlers'];
}
}
}
/**
* {@inheritdoc}
*/
public function postSave(WebformSubmissionInterface $webform_submission, $update = TRUE) {
// This is where we launch our maestro workflow based on the configuration options for this webform.
$maestro_skip = FALSE;
if (isset($webform_submission->data['maestro_skip'])) {
if ($webform_submission->data['maestro_skip']) {
$maestro_skip = TRUE;
}
}
else {
$maestro_skip = FALSE;
}
// Only do this on NEW webforms & webforms that are not mid-workflow.
if (!$update && !$maestro_skip) {
$maestro = new MaestroEngine();
$processID = $maestro
->newProcess($this->configuration['maestro_template']);
if ($processID !== FALSE) {
if ($this->configuration['maestro_message_success'] != '') {
\Drupal::messenger()
->addStatus($this->configuration['maestro_message_success']);
}
// Set the entity identifier to attach this webform to the maestro workflow template that is put into production.
if (!MaestroEngine::createEntityIdentifier($processID, $webform_submission
->getEntityTypeId(), $webform_submission
->bundle(), 'submission', $webform_submission
->id())) {
\Drupal::messenger()
->addError($this->configuration['maestro_message_failure']);
}
}
else {
// Only show the message if our config says to do so.
if ($this->configuration['maestro_message_failure'] != '') {
\Drupal::messenger()
->addError($this->configuration['maestro_message_failure']);
}
}
}
}
/**
* {@inheritdoc}
*/
public function isExcluded() {
return $this->configFactory
->get('webform.settings')
->get('handler.excluded_handlers.' . $this->pluginDefinition['id']) ? TRUE : FALSE;
}
/**
* {@inheritdoc}
*/
public function isEnabled() {
return $this->status ? TRUE : FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
MaestroWebformHandler:: |
protected | property |
The configuration object factory. Overrides WebformHandlerBase:: |
|
MaestroWebformHandler:: |
protected | property | The current user. | |
MaestroWebformHandler:: |
protected | property | The webform element plugin manager. | |
MaestroWebformHandler:: |
protected | property | The language manager. | |
MaestroWebformHandler:: |
protected | property | A mail manager for sending email. | |
MaestroWebformHandler:: |
protected | property | The module handler. | |
MaestroWebformHandler:: |
protected | property | The webform theme manager. | |
MaestroWebformHandler:: |
protected | property |
The webform token manager. Overrides WebformHandlerBase:: |
|
MaestroWebformHandler:: |
public | function |
Form constructor. Overrides WebformHandlerBase:: |
|
MaestroWebformHandler:: |
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 WebformHandlerBase:: |
|
MaestroWebformHandler:: |
public | function |
Gets default configuration for this plugin. Overrides WebformHandlerBase:: |
|
MaestroWebformHandler:: |
public | function |
Returns a render array summarizing the configuration of the webform handler. Overrides WebformHandlerBase:: |
|
MaestroWebformHandler:: |
public | function |
Returns the webform handler enabled indicator. Overrides WebformHandlerBase:: |
|
MaestroWebformHandler:: |
public | function |
Checks if the handler is excluded via webform.settings. Overrides WebformHandlerBase:: |
|
MaestroWebformHandler:: |
public | function |
Acts on a saved webform submission before the insert or update hook is invoked. Overrides WebformHandlerBase:: |
|
MaestroWebformHandler:: |
public | function |
Form submission handler. Overrides WebformHandlerBase:: |
|
MaestroWebformHandler:: |
public | function |
Submit webform submission form. Overrides WebformHandlerBase:: |
|
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. | |
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 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. Overrides WebformEntityInjectionTrait:: |
|
WebformHandlerBase:: |
protected | property |
The webform submission. Overrides WebformEntityInjectionTrait:: |
|
WebformHandlerBase:: |
protected | property | The weight of the webform handler. | |
WebformHandlerBase:: |
public | function |
Controls entity operation access to webform submission. Overrides WebformHandlerInterface:: |
1 |
WebformHandlerBase:: |
public | function |
Controls entity operation access to webform submission element. Overrides WebformHandlerInterface:: |
1 |
WebformHandlerBase:: |
public | function |
Alter webform element. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Alter webform submission webform elements. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Alter webform submission form. Overrides WebformHandlerInterface:: |
3 |
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 | function |
Confirm webform submission form. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on a element after it has been created. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on handler after it has been created and added to webform. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on a element after it has been deleted. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on handler after it has been removed. Overrides WebformHandlerInterface:: |
3 |
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 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 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 |
Alter/override a webform submission webform settings. Overrides WebformHandlerInterface:: |
3 |
WebformHandlerBase:: |
public | function |
Acts on a webform submission after it is created. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on deleted a webform submission before the delete hook is invoked. Overrides WebformHandlerInterface:: |
4 |
WebformHandlerBase:: |
public | function |
Acts on loaded webform submission. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on webform submissions after they are purged. Overrides WebformHandlerInterface:: |
1 |
WebformHandlerBase:: |
public | function |
Changes the values of an entity before it is created. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on a webform submission before they are deleted and before hooks are invoked. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on an webform submission about to be shown on a webform submission form. Overrides WebformHandlerInterface:: |
|
WebformHandlerBase:: |
public | function |
Prepares variables for webform confirmation templates. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on webform submissions before they are purged. Overrides WebformHandlerInterface:: |
1 |
WebformHandlerBase:: |
public | function |
Acts on a webform submission before the presave hook is invoked. Overrides WebformHandlerInterface:: |
2 |
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 |
Acts on a element after it has been updated. Overrides WebformHandlerInterface:: |
2 |
WebformHandlerBase:: |
public | function |
Acts on handler after it has been updated. Overrides WebformHandlerInterface:: |
3 |
WebformHandlerBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
3 |
WebformHandlerBase:: |
public | function |
Validate webform submission form. Overrides WebformHandlerInterface:: |
2 |
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 |