DefaultStateHandler.php in Conditional Fields 4.x
File
src/Plugin/conditional_fields/handler/DefaultStateHandler.php
View source
<?php
namespace Drupal\conditional_fields\Plugin\conditional_fields\handler;
use Drupal\conditional_fields\ConditionalFieldsHandlerBase;
use Drupal\conditional_fields\ConditionalFieldsInterface;
class DefaultStateHandler extends ConditionalFieldsHandlerBase {
public function statesHandler($field, $field_info, $options) {
$values = [];
$values_array = $this
->getConditionValues($options);
$values_set = $options['values_set'];
switch ($values_set) {
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET:
$values[$options['condition']] = $options['value_form'];
break;
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX:
$values[$options['condition']] = [
'regex' => $options['regex'],
];
break;
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR:
$values[$options['condition']] = [
'xor' => $values_array,
];
break;
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND:
$values[$options['condition']] = count($values_array) == 1 ? $values_array[0] : $values_array;
break;
default:
if ($options['values_set'] == ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT) {
$options['state'] = '!' . $options['state'];
}
if (!empty($values_array)) {
foreach ($values_array as $value) {
$values[] = [
'value' => $value,
];
}
}
else {
$values = $options['values'];
}
break;
}
$state = [
$options['state'] => [
$options['selector'] => $values,
],
];
return $state;
}
}