You are here

public function SmartDateTimezoneWidget::settingsForm in Smart Date 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/Field/FieldWidget/SmartDateTimezoneWidget.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateTimezoneWidget::settingsForm()
  2. 3.0.x src/Plugin/Field/FieldWidget/SmartDateTimezoneWidget.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateTimezoneWidget::settingsForm()
  3. 3.1.x src/Plugin/Field/FieldWidget/SmartDateTimezoneWidget.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateTimezoneWidget::settingsForm()
  4. 3.2.x src/Plugin/Field/FieldWidget/SmartDateTimezoneWidget.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateTimezoneWidget::settingsForm()
  5. 3.3.x src/Plugin/Field/FieldWidget/SmartDateTimezoneWidget.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateTimezoneWidget::settingsForm()
  6. 3.4.x src/Plugin/Field/FieldWidget/SmartDateTimezoneWidget.php \Drupal\smart_date\Plugin\Field\FieldWidget\SmartDateTimezoneWidget::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 SmartDateDefaultWidget::settingsForm

File

src/Plugin/Field/FieldWidget/SmartDateTimezoneWidget.php, line 68

Class

SmartDateTimezoneWidget
Plugin implementation of the 'smartdate_timezone' widget.

Namespace

Drupal\smart_date\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $element = parent::settingsForm($form, $form_state);
  $element['default_tz'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Default timezone'),
    '#default_value' => $this
      ->getSetting('default_tz'),
    '#options' => [
      '' => $this
        ->t('Site default (ignores any user override)'),
      'user' => $this
        ->t("User's timezone, defaulting to site (always saved)"),
      'custom' => $this
        ->t('A custom timezone (always saved)'),
    ],
  ];
  $custom_tz = $this
    ->getSetting('custom_tz') ? $this
    ->getSetting('custom_tz') : $this
    ->getSiteTimezone();
  $element['custom_tz'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Custom timezone'),
    '#default_value' => $custom_tz,
    '#options' => $this
      ->getTimezones(),
    '#states' => [
      // Show this select only if the 'default_tz' select is set to custom.
      'visible' => [
        'select[name$="[settings][default_tz]"]' => [
          'value' => 'custom',
        ],
      ],
    ],
  ];
  return $element;
}