You are here

class Number in Conditional Fields 4.x

Same name and namespace in other branches
  1. 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

Expanded class hierarchy of Number

File

src/Plugin/conditional_fields/handler/Number.php, line 15

Namespace

Drupal\conditional_fields\Plugin\conditional_fields\handler
View 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

Namesort descending Modifiers Type Description Overrides
ConditionalFieldsHandlerBase::getConditionValues public function Get values form the condition options. Overrides ConditionalFieldsHandlersPluginInterface::getConditionValues
ConditionalFieldsHandlerBase::getWidgetValue public function Get values from widget settings for plugin. Overrides ConditionalFieldsHandlersPluginInterface::getWidgetValue 5
Number::statesHandler public function Executes states handler according to conditional fields settings. Overrides ConditionalFieldsHandlersPluginInterface::statesHandler