public static function WebformElementAttributes::validateWebformElementAttributes in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Element/WebformElementAttributes.php \Drupal\webform\Element\WebformElementAttributes::validateWebformElementAttributes()
Validates element attributes.
File
- src/
Element/ WebformElementAttributes.php, line 148
Class
- WebformElementAttributes
- Provides a webform element for element attributes.
Namespace
Drupal\webform\ElementCode
public static function validateWebformElementAttributes(&$element, FormStateInterface $form_state, &$complete_form) {
$values = $element['#value'];
$attributes = [];
if ($values['class']) {
if (isset($element['class']['select'])) {
$class = $element['class']['select']['#value'];
$class_other = $element['class']['other']['#value'];
if (isset($class[WebformSelectOther::OTHER_OPTION])) {
unset($class[WebformSelectOther::OTHER_OPTION]);
if ($class_other) {
$class_other = preg_split('/[ ]+/', $class_other);
$class += array_combine($class_other, $class_other);
}
}
if ($class) {
$attributes['class'] = array_values($class);
}
}
else {
$attributes['class'] = preg_split('/[ ]+/', $values['class']);
}
}
if ($values['style']) {
$attributes['style'] = $values['style'];
}
if (!empty($values['attributes'])) {
$attributes += Yaml::decode($values['attributes']);
}
$form_state
->setValueForElement($element['class'], NULL);
$form_state
->setValueForElement($element['style'], NULL);
$form_state
->setValueForElement($element['attributes'], NULL);
$element['#value'] = $attributes;
$form_state
->setValueForElement($element, $attributes);
}