public static function YamlFormLikert::validateYamlFormLikert in YAML Form 8
Validates a likert element.
File
- src/
Element/ YamlFormLikert.php, line 151
Class
- YamlFormLikert
- Provides a form element for a likert scale.
Namespace
Drupal\yamlform\ElementCode
public static function validateYamlFormLikert(&$element, FormStateInterface $form_state, &$complete_form) {
$value = $element['#value'];
if (!empty($element['#required'])) {
foreach ($element['#questions'] as $question_key => $question_title) {
if (empty($value[$question_key])) {
$form_state
->setError($element['table'][$question_key]['likert_question'], t('@name field is required.', [
'@name' => $question_title,
]));
}
}
}
$form_state
->setValueForElement($element, $value);
}