public static function WebformElementOptions::validateWebformElementOptions in Webform 8.5
Same name and namespace in other branches
- 6.x src/Element/WebformElementOptions.php \Drupal\webform\Element\WebformElementOptions::validateWebformElementOptions()
Validates a webform element options element.
File
- src/
Element/ WebformElementOptions.php, line 153
Class
- WebformElementOptions
- Provides a form element for managing webform element options.
Namespace
Drupal\webform\ElementCode
public static function validateWebformElementOptions(&$element, FormStateInterface $form_state, &$complete_form) {
$options_value = NestedArray::getValue($form_state
->getValues(), $element['options']['#parents']);
$custom_value = NestedArray::getValue($form_state
->getValues(), $element['custom']['#parents']);
$value = $options_value;
if ($options_value === static::CUSTOM_OPTION) {
try {
$value = is_string($custom_value) ? Yaml::decode($custom_value) : $custom_value;
} catch (\Exception $exception) {
// Do nothing since the 'webform_codemirror' element will have already
// captured the validation error.
}
}
if (Element::isVisibleElement($element) && $element['#required'] && empty($value)) {
WebformElementHelper::setRequiredError($element, $form_state);
}
$form_state
->setValueForElement($element['options'], NULL);
$form_state
->setValueForElement($element['custom'], NULL);
$element['#value'] = $value;
$form_state
->setValueForElement($element, $value);
}