You are here

public function DateRecurModularSierraWidget::settingsForm in Recurring Date Field Modular Widgets 8

Same name and namespace in other branches
  1. 3.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::settingsForm()
  2. 2.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::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/DateRecurModularSierraWidget.php, line 207

Class

DateRecurModularSierraWidget
Date recur sierra widget.

Namespace

Drupal\date_recur_modular\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) : array {
  $form = parent::settingsForm($form, $form_state);
  $interpreterOptions = array_map(function (DateRecurInterpreterInterface $interpreter) : string {
    return $interpreter
      ->label() ?? (string) $this
      ->t('- Missing label -');
  }, $this->dateRecurInterpreterStorage
    ->loadMultiple());
  $form['interpreter'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Recurring date interpreter'),
    '#description' => $this
      ->t('Choose a plugin for converting rules into a human readable description.'),
    '#default_value' => $this
      ->getSetting('interpreter'),
    '#options' => $interpreterOptions,
    '#required' => FALSE,
    '#empty_option' => $this
      ->t('- Do not show interpreted rule -'),
  ];
  $dateFormatOptions = array_map(function (DateFormatInterface $dateFormat) {
    $time = new DrupalDateTime();
    $format = $this->dateFormatter
      ->format($time
      ->getTimestamp(), $dateFormat
      ->id());
    return $dateFormat
      ->label() . ' (' . $format . ')';
  }, $this->dateFormatStorage
    ->loadMultiple());
  $form['date_format_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Occurrence date format'),
    '#description' => $this
      ->t('Date format type to display occurrences and excluded occurrences.'),
    '#options' => $dateFormatOptions,
    '#default_value' => $this
      ->getSetting('date_format_type'),
  ];
  $form['occurrences_modal'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Whether to enable occurrences button'),
    '#default_value' => $this
      ->isOccurrencesModalEnabled(),
  ];
  return $form;
}