You are here

public function DateDefault::statesHandler in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 src/Plugin/conditional_fields/handler/DateDefault.php \Drupal\conditional_fields\Plugin\conditional_fields\handler\DateDefault::statesHandler()

Executes states handler according to conditional fields settings.

Overrides ConditionalFieldsHandlersPluginInterface::statesHandler

File

src/Plugin/conditional_fields/handler/DateDefault.php, line 22

Class

DateDefault
Provides states handler for date combos.

Namespace

Drupal\conditional_fields\Plugin\conditional_fields\handler

Code

public function statesHandler($field, $field_info, $options) {
  $state = [];
  $value = $this
    ->getWidgetValue($options['value_form']);
  $date_obj = new DrupalDateTime($value);
  switch ($options['values_set']) {
    case ConditionalFieldsInterface::CONDITIONAL_FIELDS_DEPENDENCY_VALUES_WIDGET:

      // Just split DATETIME_DATETIME_STORAGE_FORMAT on date and time.
      $date = $date_obj
        ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);

      // @todo Support time.
      // Need to check selector and create one more state for it.
      // $time = $date_obj->tesformat('H:i:s');.
      $state[$options['state']][$options['selector']]['value'] = $date;
      break;
    default:
      break;
  }
  return $state;
}