public function Select::statesHandler in Conditional Fields 8
Same name and namespace in other branches
- 4.x src/Plugin/conditional_fields/handler/Select.php \Drupal\conditional_fields\Plugin\conditional_fields\handler\Select::statesHandler()
Executes states handler according to conditional fields settings.
Overrides ConditionalFieldsHandlersPluginInterface::statesHandler
File
- src/
Plugin/ conditional_fields/ handler/ Select.php, line 25
Class
- Select
- Provides states handler for multiple select lists.
Namespace
Drupal\conditional_fields\Plugin\conditional_fields\handlerCode
public function statesHandler($field, $field_info, $options) {
$state = [];
$select_states = [];
$values_array = $this
->getConditionValues($options);
switch ($options['values_set']) {
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET:
return $this
->widgetCase($field, $options);
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND:
if (isset($state[$options['state']][$options['selector']]['value'])) {
$state[$options['state']][$options['selector']]['value'] = (array) $state[$options['state']][$options['selector']]['value'];
}
else {
$state[$options['state']][$options['selector']]['value'] = $values_array;
}
break;
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR:
$input_states[$options['selector']] = [
$options['condition'] => [
'xor' => $values_array,
],
];
$state[$options['state']] = $input_states;
break;
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX:
$select_states[$options['state']][] = [
$options['selector'] => [
$options['condition'] => [
'regex' => $options['regex'],
],
],
];
$state = $select_states;
break;
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT:
$options['state'] = '!' . $options['state'];
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR:
foreach ((array) $options['values'] as $value) {
$select_states[$options['state']][$options['selector']][] = [
$options['condition'] => $value,
];
}
$state = $select_states;
break;
}
return $state;
}