function maestro_webform_webform_type_task_submit in Maestro 8.2
Same name and namespace in other branches
- 3.x modules/maestro_webform/maestro_webform.module \maestro_webform_webform_type_task_submit()
Implements hook_webform_type_task_submit().
1 string reference to 'maestro_webform_webform_type_task_submit'
- maestro_webform_form_alter in modules/
maestro_webform/ maestro_webform.module - Implements hook_form_alter().
File
- modules/
maestro_webform/ maestro_webform.module, line 95 - Contains maestro_webform.module.
Code
function maestro_webform_webform_type_task_submit(&$form, FormStateInterface $form_state) {
// We have hooked into the webform submission by explicitly telling the webform to execute
// this submission handler
// get the identifiers here for Maestro.
$maestroElements = $form_state
->getValue('maestro');
if ($maestroElements) {
$queueID = $maestroElements['queue_id'];
$processID = $maestroElements['process_id'];
$webformType = $maestroElements['type'];
$templateTask = MaestroEngine::getTemplateTaskByQueueID($queueID);
if ($templateTask) {
// We have a valid submission and can attach to the template task
// We determine if the entity identifier exists in our maestro_entity_identifiers entity.
// If it doesn't exist, we create it.
if (!MaestroEngine::getEntityIdentiferByUniqueID($processID, $templateTask['data']['unique_id'])) {
// Create the entry in the process variable
// Get the Webform identifiers here:
$form_object = $form_state
->getFormObject();
$webform_submission = $form_object
->getEntity();
MaestroEngine::createEntityIdentifier($processID, $webform_submission
->getEntityTypeId(), $webform_submission
->bundle(), $templateTask['data']['unique_id'], $webform_submission
->id());
}
else {
// This is the case where the entry already exists. Need to do anything?
}
// Now that the process variable has been set and we've saved the webform, we can complete the task.
MaestroEngine::completeTask($queueID, \Drupal::currentUser()
->id());
$response = new TrustedRedirectResponse('/taskconsole');
if (isset($templateTask['data']['redirect_to']) && $templateTask['data']['redirect_to'] != '') {
$response = new TrustedRedirectResponse('/' . $templateTask['data']['redirect_to']);
$form_state
->setResponse($response);
$form_state
->setRedirect(Url::fromUserInput('/' . $templateTask['data']['redirect_to']));
}
else {
$response = new TrustedRedirectResponse('/taskconsole');
$form_state
->setResponse($response);
$form_state
->setRedirect(Url::fromUserInput('/taskconsole'));
}
}
}
else {
// can't bind to a template. Throw an error?
}
}