You are here

public static function YamlFormElementStates::convertFormValuesToStatesArray in YAML Form 8

Convert form values to states array.

Parameters

array $values: Submitted form values to converted to states array.

Return value

array An associative array of states.

2 calls to YamlFormElementStates::convertFormValuesToStatesArray()
YamlFormElementStates::convertFormValuesToFormApiStates in src/Element/YamlFormElementStates.php
Convert form values to states array.
YamlFormElementStates::valueCallback in src/Element/YamlFormElementStates.php
Determines how user input is mapped to an element's #value property.

File

src/Element/YamlFormElementStates.php, line 611

Class

YamlFormElementStates
Provides a form element to edit an element's #states.

Namespace

Drupal\yamlform\Element

Code

public static function convertFormValuesToStatesArray(array $values = []) {
  $index = 0;
  $states = [];
  foreach ($values as $value) {
    if (isset($value['state'])) {
      $index++;
      $states[$index] = [
        'state' => $value['state'],
        'operator' => $value['operator'],
        'conditions' => [],
      ];
    }
    else {
      $selector = $value['selector']['select'];
      if ($selector == YamlFormSelectOther::OTHER_OPTION) {
        $selector = $value['selector']['other'];
      }
      $value['selector'] = $selector;
      $states[$index]['conditions'][] = $value;
    }
  }
  return $states;
}