class Number in Conditional Fields 4.x
Same name and namespace in other branches
- 8 src/Plugin/conditional_fields/handler/Number.php \Drupal\conditional_fields\Plugin\conditional_fields\handler\Number
Provides states handler for Number (integer, decimal and float).
Plugin annotation
@ConditionalFieldsHandler(
id = "states_handler_number",
)
Hierarchy
- class \Drupal\conditional_fields\ConditionalFieldsHandlerBase implements ConditionalFieldsHandlersPluginInterface
- class \Drupal\conditional_fields\Plugin\conditional_fields\handler\Number
Expanded class hierarchy of Number
File
- src/
Plugin/ conditional_fields/ handler/ Number.php, line 15
Namespace
Drupal\conditional_fields\Plugin\conditional_fields\handlerView source
class Number extends ConditionalFieldsHandlerBase {
/**
* {@inheritdoc}
*/
public function statesHandler($field, $field_info, $options) {
$state = [];
switch ($options['values_set']) {
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET:
if ($options['field_cardinality'] == 1) {
$state[$options['state']][$options['selector']] = [
'value' => $this
->getWidgetValue($options['value_form']),
];
}
else {
$values = array_column($this
->getWidgetValue($options['value_form']), 'value');
foreach ($values as $key => $value) {
if (empty($value)) {
continue;
}
$selector = str_replace('[0]', "[{$key}]", $options['selector']);
$state[$options['state']][$selector] = [
'value' => $value,
];
}
}
return $state;
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_AND:
// Implemented in DefaultStateHandler.
return $state;
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_XOR:
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_REGEX:
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_NOT:
case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR:
// Implemented in DefaultStateHandler.
break;
}
return $state;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConditionalFieldsHandlerBase:: |
public | function |
Get values form the condition options. Overrides ConditionalFieldsHandlersPluginInterface:: |
|
ConditionalFieldsHandlerBase:: |
public | function |
Get values from widget settings for plugin. Overrides ConditionalFieldsHandlersPluginInterface:: |
5 |
Number:: |
public | function |
Executes states handler according to conditional fields settings. Overrides ConditionalFieldsHandlersPluginInterface:: |