You are here

public static function WebformElementStates::validateWebformElementStates in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformElementStates.php \Drupal\webform\Element\WebformElementStates::validateWebformElementStates()

Validates webform states element.

File

src/Element/WebformElementStates.php, line 726

Class

WebformElementStates
Provides a webform element to edit an element's #states.

Namespace

Drupal\webform\Element

Code

public static function validateWebformElementStates(&$element, FormStateInterface $form_state, &$complete_form) {
  if (isset($element['states']['#value']) && is_string($element['states']['#value'])) {
    $states = Yaml::decode($element['states']['#value']);
  }
  else {
    $errors = [];
    $states = static::convertElementValueToFormApiStates($element, $errors);
    if ($errors) {
      $form_state
        ->setError($element, reset($errors));
    }
  }
  $form_state
    ->setValueForElement($element, NULL);
  $element['#value'] = $states;
  $form_state
    ->setValueForElement($element, $states);
}