public function MoveBlockForm::ajaxSubmit in Layout Builder Restrictions 8.2
Submit form dialog #ajax callback.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
\Drupal\Core\Ajax\AjaxResponse An AJAX response that display validation error messages or represents a successful submission.
Overrides AjaxFormHelperTrait::ajaxSubmit
File
- src/
Form/ MoveBlockForm.php, line 53
Class
- MoveBlockForm
- Provides a form for moving a block.
Namespace
Drupal\layout_builder_restrictions\FormCode
public function ajaxSubmit(array &$form, FormStateInterface $form_state) {
if ($form_state
->hasAnyErrors()) {
$build_info = $form_state
->getBuildInfo();
$response = new AjaxResponse();
$content = "";
foreach ($form_state
->getErrors() as $error) {
$content .= '<p>' . $error . '</p>';
}
$build['error'] = [
'#markup' => $content,
];
$build['back_button'] = [
'#type' => 'link',
'#url' => Url::fromRoute('layout_builder.move_block_form', [
'section_storage_type' => $build_info['args'][0]
->getPluginId(),
'section_storage' => $build_info['args'][0]
->getStorageId(),
'delta' => $build_info['args'][1],
'region' => $build_info['args'][2],
'uuid' => $build_info['args'][3],
]),
'#title' => $this
->t('Back'),
'#attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'dialog',
'data-dialog-renderer' => 'off_canvas',
],
];
$response
->addCommand(new OpenOffCanvasDialogCommand("Content cannot be placed.", $build));
}
else {
$response = $this
->successfulAjaxSubmit($form, $form_state);
}
return $response;
}