public static function WebformOptions::validateWebformOptions in Webform 8.5
Same name and namespace in other branches
- 6.x src/Element/WebformOptions.php \Drupal\webform\Element\WebformOptions::validateWebformOptions()
Validates webform options element.
File
- src/
Element/ WebformOptions.php, line 189
Class
- WebformOptions
- Provides a webform element to assist in creation of options.
Namespace
Drupal\webform\ElementCode
public static function validateWebformOptions(&$element, FormStateInterface $form_state, &$complete_form) {
if ($form_state
->hasAnyErrors()) {
return;
}
$options_value = NestedArray::getValue($form_state
->getValues(), $element['options']['#parents']);
if (is_string($options_value)) {
$options = Yaml::decode($options_value);
}
else {
$options = static::convertValuesToOptions($options_value, $element['#options_description']);
}
// Validate required options.
if (!empty($element['#required']) && empty($options)) {
WebformElementHelper::setRequiredError($element, $form_state);
return;
}
$element['#value'] = $options;
$form_state
->setValueForElement($element, $options);
}