public function MaestroInteractiveFormBase::submitForm in Maestro 8.2
Same name and namespace in other branches
- 3.x src/Form/MaestroInteractiveFormBase.php \Drupal\maestro\Form\MaestroInteractiveFormBase::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ MaestroInteractiveFormBase.php, line 49
Class
- MaestroInteractiveFormBase
- The Maestro Interactive task form base.
Namespace
Drupal\maestro\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// What if this interactive task is being executed by someone not in a modal and they're faking out that
// it is infact a modal? Let's check if they're even supposed to be here and if this is still a valid task.
// We created this form element. It must be there.
$queueID = intval($form_state
->getValue('maestro_queue_id'));
$processID = MaestroEngine::getProcessIdFromQueueId($queueID);
$task = MaestroEngine::getTemplateTaskByQueueID($queueID);
if (isset($task['data']['redirect_to'])) {
// $response = new TrustedRedirectResponse('/' . $task['data']['redirect_to']);
// $form_state->setResponse($response);
$url = Url::fromUserInput('/' . $task['data']['redirect_to'], [
'query' => [
'maestro' => 1,
'queueid' => $form_state
->getValue('queueid', 0),
],
]);
$form_state
->setRedirectUrl($url);
}
if (MaestroEngine::canUserExecuteTask($queueID, \Drupal::currentUser()
->id())) {
$queueEntry = MaestroEngine::getQueueEntryById($queueID);
$handler = $queueEntry->handler
->getString();
if ($handler != '') {
// Execute our custom submit handler - assuming a standard naming convention.
$submit_handler = $handler . '_submit';
if (function_exists($submit_handler)) {
call_user_func_array($submit_handler, [
&$form,
&$form_state,
$queueID,
]);
// Determine if the form state submission was clicked.
// If so, complete the task!
$triggeringElement = $form_state
->getTriggeringElement();
if (strstr($triggeringElement['#id'], 'edit-submit') !== FALSE && $queueID > 0) {
// This is our submit button. User wanted to complete this task. Let's do so.
// If you have a reject, you handle that in your own interactive submit handler code
// to set the appropriate task status.
MaestroEngine::completeTask($queueID, \Drupal::currentUser()
->id());
}
}
else {
// Offload to the task to do any special handling.
$task = NULL;
$task = MaestroEngine::getPluginTask($queueEntry->task_class_name
->getString(), $processID, $queueID);
if ($task != NULL) {
$task
->handleExecuteSubmit($form, $form_state);
}
}
}
else {
// Offload to the task to do any special handling.
$task = NULL;
$task = MaestroEngine::getPluginTask($queueEntry->task_class_name
->getString(), $processID, $queueID);
if ($task != NULL) {
$task
->handleExecuteSubmit($form, $form_state);
}
}
}
// Rebuild the form.
$form_state
->setRebuild(TRUE);
}