You are here

class DateFieldListWidget in Date 8

Plugin implementation of the 'date' widget.

Plugin annotation


@Plugin(
  id = "date_field_list",
  module = "date",
  label = @Translation("Select list"),
  field_types = {
    "date"
  },
  settings = {
    "date_format" = "Y-m-d",
    "date_element" = "date",
    "input_format_custom" = "",
    "increment" = 15,
    "text_parts" = {""},
    "year_range" = "-3:+3",
    "all_day_toggle" = 0
  }
)

Hierarchy

Expanded class hierarchy of DateFieldListWidget

File

date_field/lib/Drupal/date_field/Plugin/field/widget/DateFieldListWidget.php, line 36
Definition of Drupal\date_field\Plugin\field\widget\DateFieldListWidget.

Namespace

Drupal\date_field\Plugin\field\widget
View source
class DateFieldListWidget extends DateFieldWidgetBase {
  function settingsForm(array $form, array &$form_state) {
    $element = parent::settingsForm($form, $form_state);
    $element['date_format'] = array(
      '#type' => 'select',
      '#title' => t('Date entry format'),
      '#default_value' => $this
        ->getSetting('date_format'),
      '#options' => $this
        ->formatOptions(),
      '#description' => t('Control the order and format of the options users see.'),
      '#weight' => 3,
      '#fieldset' => 'date_format',
    );
    $form['all_day_toggle'] = array(
      '#type' => 'select',
      '#title' => t('All day toggle'),
      '#description' => t("Add an 'All day' checkbox to the form to allow the user to hide or show the time."),
      '#default_value' => $this
        ->getSetting('all_day_toggle'),
      '#options' => array(
        0 => t('No'),
        1 => t('Yes'),
      ),
      '#weight' => 2,
    );
    $element['advanced'] = array(
      '#type' => 'fieldset',
      '#title' => t('Advanced settings'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#fieldset' => 'date_format',
      '#weight' => 9,
    );
    $element['advanced']['text_parts'][$key] = array(
      '#type' => 'value',
      '#value' => (int) in_array($key, (array) $this
        ->getSetting('text_parts')),
    );
    $element['advanced']['text_parts'] = array(
      '#theme' => 'date_text_parts',
    );
    $text_parts = (array) $this
      ->getSetting('text_parts');
    foreach (DateGranularity::granularityNames() as $key => $value) {
      $element['advanced']['text_parts'][$key] = array(
        '#type' => 'radios',
        '#default_value' => in_array($key, $text_parts) ? 1 : 0,
        '#options' => array(
          0 => '',
          1 => '',
        ),
      );
    }
    return $element;
  }
  function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) {
    $element = parent::formElement($items, $delta, $element, $langcode, $form, $form_state);
    $element += array(
      '#type' => 'datetime',
      '#date_increment' => $this
        ->getSetting('increment'),
      '#date_text_parts' => $this
        ->getSetting('text_parts'),
      '#date_year_range' => $this
        ->getSetting('year_range'),
      '#date_all_day_toggle' => $this
        ->getSetting('all_day_toggle'),
      '#date_date_format' => $this
        ->getSetting('date_format'),
      '#date_date_element' => $this
        ->getSetting('date_element'),
    );
    return $element;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DateFieldListWidget::formElement function Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement(). Overrides DateFieldWidgetBase::formElement
DateFieldListWidget::settingsForm function Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::settingsForm(). Overrides DateFieldWidgetBase::settingsForm
DateFieldWidgetBase::defaultValueFunction public function Return the callback used to set a date default value.
DateFieldWidgetBase::formatOptions public function Return the format options used by this widget.
DateFieldWidgetBase::__construct public function Constructs a DateWidget object.