You are here

public static function WebformLikert::setRequiredError in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformLikert.php \Drupal\webform\Element\WebformLikert::setRequiredError()

Set element required error messages.

Parameters

array $element: An element.

\Drupal\Core\Form\FormStateInterface $form_state: The current form's state.

1 call to WebformLikert::setRequiredError()
WebformLikert::validateWebformLikert in src/Element/WebformLikert.php
Validates a likert element.

File

src/Element/WebformLikert.php, line 327

Class

WebformLikert
Provides a webform element for a likert scale.

Namespace

Drupal\webform\Element

Code

public static function setRequiredError(array &$element, FormStateInterface $form_state) {
  $value = $element['#value'];
  foreach ($element['#questions'] as $question_key => $question_title) {
    if (is_null($value[$question_key])) {
      $question_element =& $element['table'][$question_key]['likert_question'];
      $t_args = [
        '@name' => $question_title,
      ];
      if (!empty($element['#required_error'])) {
        $form_state
          ->setError($question_element, new FormattableMarkup($element['#required_error'], $t_args));
      }
      else {
        $form_state
          ->setError($question_element, t('@name field is required.', $t_args));
      }
    }
  }
}