public function MaestroTemplateBuilderAddNew::submitForm in Maestro 8.2
Same name and namespace in other branches
- 3.x modules/maestro_template_builder/src/Form/MaestroTemplateBuilderAddNew.php \Drupal\maestro_template_builder\Form\MaestroTemplateBuilderAddNew::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/ MaestroTemplateBuilderAddNew.php, line 65
Class
- MaestroTemplateBuilderAddNew
- Maestro Template Builder Add New form.
Namespace
Drupal\maestro_template_builder\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Do we have any errors? if so, handle them by returning the form's HTML and replacing the form.
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('#template-add-new-form', $form));
return $response;
}
else {
$templateMachineName = $form_state
->getValue('template_machine_name');
$id = $form_state
->getValue('task_machine_name');
$label = $form_state
->getValue('task_label');
$type = $form_state
->getValue('choose_task');
// Create the new task entry in the template.
$template = MaestroEngine::getTemplate($templateMachineName);
$this_task = MaestroEngine::getPluginTask($type);
$capabilities = $this_task
->getTemplateBuilderCapabilities();
foreach ($capabilities as $key => $c) {
$capabilities[$key] = 'maestro_template_' . $c;
}
$template->tasks[$id] = [
'id' => $id,
'label' => $label,
'tasktype' => $type,
'nextstep' => '',
'nextfalsestep' => '',
'top' => '15',
'left' => '15',
'assignby' => 'fixed',
'assignto' => '',
'raphael' => '',
'to' => '',
'pointedfrom' => '',
'falsebranch' => '',
'lines' => [],
];
// We need to have this template validated now.
$template->validated = FALSE;
$template
->save();
$response = new AjaxResponse();
$response
->addCommand(new FireJavascriptCommand('signalValidationRequired', []));
$response
->addCommand(new FireJavascriptCommand('addNewTask', [
'id' => $id,
'label' => $label,
'type' => $type,
'capabilities' => $capabilities,
'uilabel' => $this
->t(str_replace('Maestro', '', $type)),
]));
$response
->addCommand(new CloseModalDialogCommand());
return $response;
}
}