protected static function WebformElementStates::convertFormApiStatesToStatesArray in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Element/WebformElementStates.php \Drupal\webform\Element\WebformElementStates::convertFormApiStatesToStatesArray()
Convert Form API #states to states array.
Parameters
array $fapi_states: An associative array containing Form API #states.
Return value
array An associative array of states.
2 calls to WebformElementStates::convertFormApiStatesToStatesArray()
- WebformElementStates::processWebformStates in src/
Element/ WebformElementStates.php - Expand an email confirm field into two HTML5 email elements.
- 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 775
Class
- WebformElementStates
- Provides a webform element to edit an element's #states.
Namespace
Drupal\webform\ElementCode
protected static function convertFormApiStatesToStatesArray(array $fapi_states) {
$index = 0;
$states = [];
foreach ($fapi_states as $state => $conditions) {
$states[$index] = [
'state' => $state,
'operator' => 'and',
'conditions' => [],
];
foreach ($conditions as $condition_key => $condition_value) {
if (is_string($condition_key)) {
$states[$index]['conditions'][] = static::getStatesArrayCondition($condition_key, $condition_value);
}
elseif (is_string($condition_value)) {
$states[$index]['operator'] = $condition_value;
}
else {
foreach ($condition_value as $subcondition_key => $subcondition_value) {
$states[$index]['conditions'][] = static::getStatesArrayCondition($subcondition_key, $subcondition_value);
}
}
}
$index++;
}
return $states;
}