public static function WebformElementMultiple::validateWebformElementMultiple in Webform 8.5
Same name and namespace in other branches
- 6.x src/Element/WebformElementMultiple.php \Drupal\webform\Element\WebformElementMultiple::validateWebformElementMultiple()
Validates element multiple.
File
- src/
Element/ WebformElementMultiple.php, line 114
Class
- WebformElementMultiple
- Provides a webform element for element multiple property.
Namespace
Drupal\webform\ElementCode
public static function validateWebformElementMultiple(&$element, FormStateInterface $form_state, &$complete_form) {
if (!Element::isVisibleElement($element)) {
$multiple = $element['#value'];
}
elseif (!empty($element['#disabled'])) {
$multiple = $element['#default_value'];
}
else {
$cardinality = (int) $element['#value']['container']['cardinality'];
$cardinality_number = (int) $element['#value']['container']['cardinality_number'];
if ($cardinality === WebformMultiple::CARDINALITY_UNLIMITED) {
$multiple = WebformMultiple::CARDINALITY_UNLIMITED;
}
else {
$multiple = $cardinality_number;
}
}
if ($multiple === WebformMultiple::CARDINALITY_UNLIMITED) {
$multiple = TRUE;
}
elseif ($multiple === 1) {
$multiple = FALSE;
}
$form_state
->setValueForElement($element['container']['cardinality'], NULL);
$form_state
->setValueForElement($element['container']['cardinality_number'], NULL);
$element['#value'] = $multiple;
$form_state
->setValueForElement($element, $multiple);
}