You are here

function DateTimeDatelistWidget::settingsForm in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php \Drupal\datetime\Plugin\Field\FieldWidget\DateTimeDatelistWidget::settingsForm()

Returns a form to configure settings for the widget.

Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. The field_ui module takes care of handling submitted form values.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form definition for the widget settings.

Overrides WidgetBase::settingsForm

File

core/modules/datetime/src/Plugin/Field/FieldWidget/DateTimeDatelistWidget.php, line 92
Contains \Drupal\datetime\Plugin\Field\FieldWidget\DateTimeDatelistWidget.

Class

DateTimeDatelistWidget
Plugin implementation of the 'datetime_datelist' widget.

Namespace

Drupal\datetime\Plugin\Field\FieldWidget

Code

function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);
  $element['date_order'] = array(
    '#type' => 'select',
    '#title' => t('Date part order'),
    '#default_value' => $this
      ->getSetting('date_order'),
    '#options' => array(
      'MDY' => t('Month/Day/Year'),
      'DMY' => t('Day/Month/Year'),
      'YMD' => t('Year/Month/Day'),
    ),
  );
  if ($this
    ->getFieldSetting('datetime_type') == 'datetime') {
    $element['time_type'] = array(
      '#type' => 'select',
      '#title' => t('Time type'),
      '#default_value' => $this
        ->getSetting('time_type'),
      '#options' => array(
        '24' => t('24 hour time'),
        '12' => t('12 hour time'),
      ),
    );
    $element['increment'] = [
      '#type' => 'select',
      '#title' => t('Time increments'),
      '#default_value' => $this
        ->getSetting('increment'),
      '#options' => [
        1 => t('1 minute'),
        5 => t('5 minute'),
        10 => t('10 minute'),
        15 => t('15 minute'),
        30 => t('30 minute'),
      ],
    ];
  }
  else {
    $element['time_type'] = array(
      '#type' => 'hidden',
      '#value' => 'none',
    );
    $element['increment'] = [
      '#type' => 'hidden',
      '#value' => $this
        ->getSetting('increment'),
    ];
  }
  return $element;
}