You are here

public static function YamlFormOtherBase::setElementError in YAML Form 8

Set element required error.

Parameters

array $element: The form element.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

1 call to YamlFormOtherBase::setElementError()
YamlFormOtherBase::validateYamlFormOther in src/Element/YamlFormOtherBase.php
Validates an other element.

File

src/Element/YamlFormOtherBase.php, line 224

Class

YamlFormOtherBase
Base class for form other element.

Namespace

Drupal\yamlform\Element

Code

public static function setElementError(&$element, FormStateInterface $form_state) {
  if (isset($element['#required_error'])) {
    $form_state
      ->setError($element, $element['#required_error']);
  }
  elseif (isset($element['#title'])) {
    $form_state
      ->setError($element, t('@name field is required.', [
      '@name' => $element['#title'],
    ]));
  }
  else {
    $form_state
      ->setError($element);
  }
}