You are here

protected static function WebformElementStates::convertFormValuesToStatesArray in Webform 6.x

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

Convert webform values to states array.

Parameters

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

Return value

array An associative array of states.

2 calls to WebformElementStates::convertFormValuesToStatesArray()
WebformElementStates::convertElementValueToFormApiStates in src/Element/WebformElementStates.php
Convert an element's submitted value to Form API #states.
WebformElementStates::valueCallback in src/Element/WebformElementStates.php
Determines how user input is mapped to an element's #value property.

File

src/Element/WebformElementStates.php, line 969

Class

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

Namespace

Drupal\webform\Element

Code

protected static function convertFormValuesToStatesArray(array $values = []) {
  $index = 0;
  $states = [];
  foreach ($values as $value) {
    if (isset($value['state'])) {
      $index++;
      $states[$index] = [
        'state' => $value['state'],
        'operator' => isset($value['operator']) ? $value['operator'] : 'and',
        'conditions' => [],
      ];
    }
    else {
      $states[$index]['conditions'][] = $value;
    }
  }
  return $states;
}