public function MaestroInteractiveFormBase::completeForm in Maestro 8.2
Same name and namespace in other branches
- 3.x src/Form/MaestroInteractiveFormBase.php \Drupal\maestro\Form\MaestroInteractiveFormBase::completeForm()
Ajax callback helper funciton that simply helps us separate the save/complete of a task with an optional ajax handler to close the dialog and/or do a redirect if the user has jumped out of the modal.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the form.
File
- src/
Form/ MaestroInteractiveFormBase.php, line 120
Class
- MaestroInteractiveFormBase
- The Maestro Interactive task form base.
Namespace
Drupal\maestro\FormCode
public function completeForm(array &$form, FormStateInterface $form_state) {
$this->returnPath = $form_state
->getValue('return_path');
if ($this->returnPath == '') {
// We are making an assumption here.
$this->returnPath = '/taskconsole';
}
// We created this form element. It must be there.
$queueID = intval($form_state
->getValue('maestro_queue_id'));
$processID = MaestroEngine::getProcessIdFromQueueId($queueID);
if (MaestroEngine::canUserExecuteTask($queueID, \Drupal::currentUser()
->id())) {
if ($this->modal == 'modal') {
$response = new AjaxResponse();
$response
->addCommand(new CloseModalDialogCommand());
$response
->addCommand(new RedirectCommand($this->returnPath));
return $response;
}
else {
$response = new RedirectResponse('/' . $this->returnPath);
$response
->send();
}
}
else {
// This is the case where the task was already completed or is no longer valid for whatever reason
// This case is also here to catch the issue where the submit form handler is firing twice.
// When this fires twice in a modal scenario, we need to ensure that the modal dialog is actually shut down as the
// AjaxResponse handler loses track of the origin addCommand(s) to close the modal and redirect to the redirect location.
if ($this->modal == 'modal') {
$response = new AjaxResponse();
$response
->addCommand(new CloseModalDialogCommand());
$response
->addCommand(new RedirectCommand($this->returnPath));
return $response;
}
$response = new RedirectResponse('/' . $this->returnPath);
$response
->send();
}
}