public function MaestroTemplateBuilderEditTask::submitForm in Maestro 3.x
Same name and namespace in other branches
- 8.2 modules/maestro_template_builder/src/Form/MaestroTemplateBuilderEditTask.php \Drupal\maestro_template_builder\Form\MaestroTemplateBuilderEditTask::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
- modules/
maestro_template_builder/ src/ Form/ MaestroTemplateBuilderEditTask.php, line 61
Class
- MaestroTemplateBuilderEditTask
- Maestro Template Editor Edit a Task Form.
Namespace
Drupal\maestro_template_builder\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// If we have errors in the form, show those.
if ($form_state
->getErrors()) {
unset($form['#prefix'], $form['#suffix']);
$form['status_messages'] = [
'#type' => 'status_messages',
'#weight' => -10,
];
$response = new AjaxResponse();
// Replaces the form HTML with the validated HTML.
$response
->addCommand(new HtmlCommand('#edit-task-form', $form));
return $response;
}
else {
// This should be managed by the engine. in here for the time being.
$templateMachineName = $form_state
->getValue('template_machine_name');
$taskID = $form_state
->getValue('task_id');
$template = MaestroEngine::getTemplate($templateMachineName);
$task = MaestroEngine::getTemplateTaskByID($templateMachineName, $taskID);
$executableTask = MaestroEngine::getPluginTask($task['tasktype']);
// first, lets let the task do any specific or unique task preparations.
// Prepares any specific pieces of the task for us.
$executableTask
->prepareTaskForSave($form, $form_state, $task);
// Now the core maestro requirements like the assignments and notifications.
$result = $executableTask
->saveTask($form, $form_state, $task);
// Oh Oh. Some sort of error in saving the template.
if ($result === FALSE) {
\Drupal::messenger()
->addError(t('Error saving your task.'));
$form['status_messages'] = [
'#type' => 'status_messages',
'#weight' => -10,
];
}
}
// Rebuild the form to get an updated table of assignment information.
$form_state
->setRebuild(TRUE);
}