public static function WebformSubmissionViews::validateWebformMultiple in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Element/WebformSubmissionViews.php \Drupal\webform\Element\WebformSubmissionViews::validateWebformMultiple()
Validates webform multiple element.
Overrides WebformMultiple::validateWebformMultiple
File
- src/
Element/ WebformSubmissionViews.php, line 151
Class
- WebformSubmissionViews
- Provides a form element for selecting webform submission views.
Namespace
Drupal\webform\ElementCode
public static function validateWebformMultiple(&$element, FormStateInterface $form_state, &$complete_form) {
if (!\Drupal::moduleHandler()
->moduleExists('views')) {
$element['#value'] = [];
$form_state
->setValueForElement($element, []);
return;
}
parent::validateWebformMultiple($element, $form_state, $complete_form);
$items = NestedArray::getValue($form_state
->getValues(), $element['#parents']);
foreach ($items as $name => &$item) {
// Remove empty view references.
if ($name === '' && empty($item['view']) && empty($item['global_routes']) && empty($item['webform_routes']) && empty($item['node_routes'])) {
unset($items[$name]);
continue;
}
if ($name === '') {
$form_state
->setError($element, t('Name is required.'));
}
if (empty($item['title'])) {
$form_state
->setError($element, t('Title is required.'));
}
if (empty($item['view'])) {
$form_state
->setError($element, t('View name/display id is required.'));
}
}
$element['#value'] = $items;
$form_state
->setValueForElement($element, $items);
}