public function MaestroTemplateBuilderCanvas::submitForm in Maestro 3.x
Same name and namespace in other branches
- 8.2 modules/maestro_template_builder/src/Form/MaestroTemplateBuilderCanvas.php \Drupal\maestro_template_builder\Form\MaestroTemplateBuilderCanvas::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/ MaestroTemplateBuilderCanvas.php, line 52
Class
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-canvas', $form));
return $response;
}
else {
$templateMachineName = $form_state
->getValue('template_machine_name');
$height = $form_state
->getValue('canvas_height');
$width = $form_state
->getValue('canvas_width');
// Create the new task entry in the template.
$template = MaestroEngine::getTemplate($templateMachineName);
$template->canvas_height = $height;
$template->canvas_width = $width;
$template
->save();
$response = new AjaxResponse();
$response
->addCommand(new FireJavascriptCommand('alterCanvas', [
'height' => $height,
'width' => $width,
]));
$response
->addCommand(new CloseModalDialogCommand());
return $response;
}
}