public static function WebformOptionsCustom::validateWebformOptionsCustom in Webform 6.x
Same name and namespace in other branches
- 8.5 modules/webform_options_custom/src/Element/WebformOptionsCustom.php \Drupal\webform_options_custom\Element\WebformOptionsCustom::validateWebformOptionsCustom()
Validates an other element.
File
- modules/
webform_options_custom/ src/ Element/ WebformOptionsCustom.php, line 224
Class
- WebformOptionsCustom
- Provides an element for a selecting custom options from HTML or SVG markup.
Namespace
Drupal\webform_options_custom\ElementCode
public static function validateWebformOptionsCustom(&$element, FormStateInterface $form_state, &$complete_form) {
$value = NestedArray::getValue($form_state
->getValues(), $element['select']['#parents']);
// Determine if the element has multiple values.
$is_multiple = empty($element['#multiple']) ? FALSE : TRUE;
// Determine if the return value is empty.
if ($is_multiple) {
$is_empty = empty($value) ? TRUE : FALSE;
}
else {
$is_empty = $value === '' || $value === NULL ? TRUE : FALSE;
}
// Validate on elements with #access.
if (Element::isVisibleElement($element) && !empty($element['#required']) && $is_empty) {
WebformElementHelper::setRequiredError($element, $form_state);
}
$form_state
->setValueForElement($element['select'], NULL);
$element['#value'] = $value;
$form_state
->setValueForElement($element, $value);
}