You are here

function DateFieldListWidget::settingsForm in Date 8

Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::settingsForm().

Overrides DateFieldWidgetBase::settingsForm

File

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

Class

DateFieldListWidget
Plugin implementation of the 'date' widget.

Namespace

Drupal\date_field\Plugin\field\widget

Code

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;
}