You are here

public function PersianDateTimeDatelistWidget::settingsForm in Persian Date for Drupal 8 8

Same name and namespace in other branches
  1. 8.4 src/Plugin/Field/FieldWidget/PersianDateTimeDatelistWidget.php \Drupal\persian_date\Plugin\Field\FieldWidget\PersianDateTimeDatelistWidget::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

src/Plugin/Field/FieldWidget/PersianDateTimeDatelistWidget.php, line 91

Class

PersianDateTimeDatelistWidget
Plugin implementation of the 'datetime_datelist' widget.

Namespace

Drupal\persian_date\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);
  $element['date_order'] = [
    '#type' => 'select',
    '#title' => t('Date part order'),
    '#default_value' => $this
      ->getSetting('date_order'),
    '#options' => [
      'MDY' => t('Month/Day/Year'),
      'DMY' => t('Day/Month/Year'),
      'YMD' => t('Year/Month/Day'),
    ],
  ];
  if ($this
    ->getFieldSetting('datetime_type') == 'datetime') {
    $element['time_type'] = [
      '#type' => 'select',
      '#title' => t('Time type'),
      '#default_value' => $this
        ->getSetting('time_type'),
      '#options' => [
        '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'] = [
      '#type' => 'hidden',
      '#value' => 'none',
    ];
    $element['increment'] = [
      '#type' => 'hidden',
      '#value' => $this
        ->getSetting('increment'),
    ];
  }
  return $element;
}