You are here

protected function YamlFormDialogTrait::validateDialog in YAML Form 8

Display validation error messages in modal dialog.

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

bool|\Drupal\Core\Ajax\AjaxResponse An AJAX response that display validation error messages.

3 calls to YamlFormDialogTrait::validateDialog()
YamlFormEntityForm::submitForm in src/YamlFormEntityForm.php
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state…
YamlFormHandlerFormBase::submitForm in src/Form/YamlFormHandlerFormBase.php
Form submission handler.
YamlFormUiElementFormBase::submitForm in modules/yamlform_ui/src/Form/YamlFormUiElementFormBase.php
Form submission handler.

File

src/YamlFormDialogTrait.php, line 67

Class

YamlFormDialogTrait
Trait class form dialogs.

Namespace

Drupal\yamlform

Code

protected function validateDialog(array &$form, FormStateInterface $form_state) {
  if ($this
    ->isModalDialog() && $form_state
    ->hasAnyErrors()) {
    unset($form['#prefix'], $form['#suffix']);
    $form['status_messages'] = [
      '#type' => 'status_messages',
      '#weight' => -1000,
    ];
    $response = new AjaxResponse();
    $response
      ->addCommand(new HtmlCommand('#yamlform-dialog', $form));
    return $response;
  }
  return FALSE;
}