You are here

public static function WebformSubmissionViews::validateWebformMultiple in Webform 8.5

Same name and namespace in other branches
  1. 6.x 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\Element

Code

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);
}