You are here

class DateDefault in Conditional Fields 8

Same name and namespace in other branches
  1. 4.x src/Plugin/conditional_fields/handler/DateDefault.php \Drupal\conditional_fields\Plugin\conditional_fields\handler\DateDefault

Provides states handler for date combos.

Plugin annotation


@ConditionalFieldsHandler(
  id = "states_handler_datetime_default",
)

Hierarchy

Expanded class hierarchy of DateDefault

File

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

Namespace

Drupal\conditional_fields\Plugin\conditional_fields\handler
View source
class DateDefault extends ConditionalFieldsHandlerBase {

  /**
   * {@inheritdoc}
   */
  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;
  }

}

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
DateDefault::statesHandler public function Executes states handler according to conditional fields settings. Overrides ConditionalFieldsHandlersPluginInterface::statesHandler