You are here

public static function WebformMapping::validateWebformMapping in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Element/WebformMapping.php \Drupal\webform\Element\WebformMapping::validateWebformMapping()

Validates a mapping element.

File

src/Element/WebformMapping.php, line 188

Class

WebformMapping
Provides a mapping element.

Namespace

Drupal\webform\Element

Code

public static function validateWebformMapping(&$element, FormStateInterface $form_state, &$complete_form) {
  $value = NestedArray::getValue($form_state
    ->getValues(), $element['#parents']);

  // Filter values.
  if ($element['#filter']) {
    $value = array_filter($value);
  }

  // Note: Not validating REQUIRED_ALL because each destination element is
  // already required.
  if (Element::isVisibleElement($element) && $element['#required'] && $element['#required'] !== static::REQUIRED_ALL && empty($value)) {
    WebformElementHelper::setRequiredError($element, $form_state);
  }
  $element['#value'] = $value;
  $form_state
    ->setValueForElement($element, $value);
}