setElementErrorsFromFormState example

/** * {@inheritdoc} */
  public function handleFormErrors(array &$form, FormStateInterface $form_state) {
    // After validation check if there are errors.     if ($form_state->getErrors()) {
      // Display error messages for each element.       $this->displayErrorMessages($form$form_state);

      // Loop through and assign each element its errors.       $this->setElementErrorsFromFormState($form$form_state);
    }

    return $this;
  }

  /** * Loops through and displays all form errors. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */
Home | Imprint | This part of the site doesn't use cookies.