You are here

public static function WebformComputedBase::validateWebformComputed in Webform 6.x

Same name in this branch
  1. 6.x src/Element/WebformComputedBase.php \Drupal\webform\Element\WebformComputedBase::validateWebformComputed()
  2. 6.x src/Plugin/WebformElement/WebformComputedBase.php \Drupal\webform\Plugin\WebformElement\WebformComputedBase::validateWebformComputed()
Same name and namespace in other branches
  1. 8.5 src/Element/WebformComputedBase.php \Drupal\webform\Element\WebformComputedBase::validateWebformComputed()

Validates an computed element.

File

src/Element/WebformComputedBase.php, line 162

Class

WebformComputedBase
Provides a base class for 'webform_computed' elements.

Namespace

Drupal\webform\Element

Code

public static function validateWebformComputed(&$element, FormStateInterface $form_state, &$complete_form) {

  // Make sure the form's state value uses the computed value and not the
  // raw #value. This ensures conditional handlers are triggered using
  // the accurate computed value.
  $webform_submission = static::getWebformSubmission($element, $form_state, $complete_form);
  if ($webform_submission) {
    $value = static::computeValue($element, $webform_submission);
    $form_state
      ->setValueForElement($element['value'], NULL);
    $form_state
      ->setValueForElement($element['hidden'], NULL);
    $form_state
      ->setValueForElement($element, $value);
  }
}