You are here

public function BootstrapDatepickerBase::settingsSummary in Bootstrap Datepicker 8

Returns a short summary for the current widget settings.

If an empty result is returned, a UI can still be provided to display a settings form in case the widget has configurable settings.

Return value

array A short summary of the widget settings.

Overrides WidgetBase::settingsSummary

File

src/Plugin/Field/FieldWidget/BootstrapDatepickerBase.php, line 495

Class

BootstrapDatepickerBase
Base class for SingleDateTime widget types.

Namespace

Drupal\bootstrap_datepicker\Plugin\Field\FieldWidget

Code

public function settingsSummary() {

  // Default settings.
  $default_settings = BootstrapDatepickerBase::defaultSettings();
  $today_options = [
    'FALSE' => $this
      ->t('No'),
    'TRUE' => $this
      ->t('Yes'),
    'linked' => $this
      ->t('Linked'),
  ];
  $orientation_options = [
    'auto' => $this
      ->t('auto'),
    'top auto' => $this
      ->t('top auto'),
    'bottom auto' => $this
      ->t('bottom auto'),
    'auto left' => $this
      ->t('auto left'),
    'top left' => $this
      ->t('top left'),
    'bottom left' => $this
      ->t('bottom left'),
    'auto right' => $this
      ->t('auto right'),
    'top right' => $this
      ->t('top right'),
    'bottom right' => $this
      ->t('bottom right'),
  ];
  $day_options = [
    '0' => $this
      ->t('Sunday'),
    '1' => $this
      ->t('Monday'),
    '2' => $this
      ->t('Tuesday'),
    '3' => $this
      ->t('Wednesday'),
    '4' => $this
      ->t('Thursday'),
    '5' => $this
      ->t('Friday'),
    '6' => $this
      ->t('Saturday'),
  ];
  $period_options = [
    '0' => $this
      ->t('0 / days'),
    '1' => $this
      ->t('1 / months'),
    '2' => $this
      ->t('2 / years'),
    '3' => $this
      ->t('3 / decade'),
    '4' => $this
      ->t('4 / centuries'),
  ];
  $days_of_week_disabled = [];
  foreach ($this
    ->getSetting('days_of_week_disabled') as $value) {
    if (!empty($value)) {

      // We need to re-index to 0
      // because checkboxes array started with 1 and not 0.
      $days_of_week_disabled[] = $day_options[$value - 1];
    }
  }
  $days_of_week_disabled = implode(', ', $days_of_week_disabled);
  $days_of_week_highlighted = [];
  foreach ($this
    ->getSetting('days_of_week_highlighted') as $value) {
    if (!empty($value)) {

      // We need to re-index to 0
      // because checkboxes array started with 1 and not 0.
      $days_of_week_highlighted[] = $day_options[$value - 1];
    }
  }
  $days_of_week_highlighted = implode(', ', $days_of_week_highlighted);
  $orientation = $orientation_options[$this
    ->getSetting('orientation')];
  $start_view = $day_options[$this
    ->getSetting('start_view')];
  $week_start = $day_options[$this
    ->getSetting('week_start')];
  $min_view_mode = $period_options[$this
    ->getSetting('min_view_mode')];
  $max_view_mode = $period_options[$this
    ->getSetting('max_view_mode')];
  $today_btn = $today_options[$this
    ->getSetting('today_btn')];
  if ($this
    ->getSetting('end_date_selection') == 'date') {
    $selected_end_date = $this
      ->getSetting('end_date');
  }
  elseif ($this
    ->getSetting('end_date_selection') == 'timedelta') {
    $selected_end_date = $this
      ->getSetting('end_date_timedelta');
  }
  if ($this
    ->getSetting('start_date_selection') == 'date') {
    $selected_start_date = $this
      ->getSetting('start_date');
  }
  elseif ($this
    ->getSetting('start_date_selection') == 'timedelta') {
    $selected_start_date = $this
      ->getSetting('start_date_timedelta');
  }
  $summary = [];
  $summary[] = $this
    ->t('<strong>Basic settings:</strong>');
  $summary[] = $this
    ->t('Datepicker title: @title', [
    '@title' => !empty($this
      ->getSetting('title')) ? $this
      ->getSetting('title') : $this
      ->t('None'),
  ]);
  $summary[] = $this
    ->t('Date format: @format', [
    '@format' => !empty($this
      ->getSetting('format')) ? $this
      ->getSetting('format') : $this
      ->t('Empty'),
  ]);
  $summary[] = $this
    ->t('Language tag: @language', [
    '@language' => !empty($this
      ->getSetting('language')) ? $this
      ->getSetting('language') : $this
      ->t('Empty'),
  ]);
  $summary[] = $this
    ->t('RTL language: @rtl', [
    '@rtl' => !empty($this
      ->getSetting('rtl')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Show week days: @show_week_days', [
    '@show_week_days' => !empty($this
      ->getSetting('show_week_days')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Show today button: @today_btn', [
    '@today_btn' => $today_btn,
  ]);
  $summary[] = $this
    ->t('Week start: @week_start', [
    '@week_start' => $week_start,
  ]);
  $summary[] = $this
    ->t('Enable autoclose: @autoclose', [
    '@autoclose' => !empty($this
      ->getSetting('autoclose')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Show clear button: @clear_btn', [
    '@clear_btn' => !empty($this
      ->getSetting('clear_btn')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('<strong>Advanced settings:</strong>');
  $summary[] = $this
    ->t('Nearby year assumption: @assume_nearby_year', [
    '@assume_nearby_year' => !empty($this
      ->getSetting('assume_nearby_year')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Container to be appended: <code>@container</code>', [
    '@container' => !empty($this
      ->getSetting('container')) ? $this
      ->getSetting('container') : $this
      ->t('None'),
  ]);
  $summary[] = $this
    ->t('Show calendar weeks: @calendar_weeks', [
    '@calendar_weeks' => !empty($this
      ->getSetting('calendar_weeks')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Toggel active date: @toggle_active', [
    '@toggle_active' => !empty($this
      ->getSetting('toggle_active')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Dates disabled: @dates_disabled', [
    '@dates_disabled' => !empty($this
      ->getSetting('dates_disabled')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Disabled days in week: @days_of_week_disabled', [
    '@days_of_week_disabled' => $days_of_week_disabled,
  ]);
  $summary[] = $this
    ->t('Highlighted days in week: @days_of_week_highlighted', [
    '@days_of_week_highlighted' => $days_of_week_highlighted,
  ]);
  $summary[] = $this
    ->t('Disable touch keyboard: @disable_touch_keyboard', [
    '@disable_touch_keyboard' => !empty($this
      ->getSetting('disable_touch_keyboard')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Enabled when readonly: @enable_on_readonly', [
    '@enable_on_readonly' => !empty($this
      ->getSetting('enable_on_readonly')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('End date: @end_date', [
    '@end_date' => !empty($selected_end_date) ? $selected_end_date : $this
      ->t('Infinity'),
  ]);
  $summary[] = $this
    ->t('Force date parcing: @force_parse', [
    '@force_parse' => !empty($this
      ->getSetting('force_parse')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Immediate updates: @immediate_updates', [
    '@immediate_updates' => !empty($this
      ->getSetting('immediate_updates')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Keep empty values: @keep_empty_values', [
    '@keep_empty_values' => !empty($this
      ->getSetting('keep_empty_values')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Keyboard navigation: @keyboard_navigation', [
    '@keyboard_navigation' => !empty($this
      ->getSetting('keyboard_navigation')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Max view mode: @max_view_mode', [
    '@max_view_mode' => $max_view_mode,
  ]);
  $summary[] = $this
    ->t('Min view mode: @min_view_mode', [
    '@min_view_mode' => $min_view_mode,
  ]);
  $summary[] = $this
    ->t('Multiple dates: @multidate', [
    '@multidate' => !empty($this
      ->getSetting('multidate')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Multiple dates separator: <code>@multidate_separator</code>', [
    '@multidate_separator' => !empty($this
      ->getSetting('multidate_separator')) ? $this
      ->getSetting('multidate_separator') : $this
      ->t('None'),
  ]);
  $summary[] = $this
    ->t('Orientation: @orientation', [
    '@orientation' => $orientation,
  ]);
  $summary[] = $this
    ->t('Start date: @start_date', [
    '@start_date' => !empty($selected_start_date) ? $selected_start_date : $this
      ->t('Infinity'),
  ]);
  $summary[] = $this
    ->t('Start view: @start_view', [
    '@start_view' => $start_view,
  ]);
  $summary[] = $this
    ->t('Highlight today: @today_highlight', [
    '@today_highlight' => !empty($this
      ->getSetting('today_highlight')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Update view date: @update_view_date', [
    '@update_view_date' => !empty($this
      ->getSetting('update_view_date')) ? $this
      ->t('Yes') : $this
      ->t('No'),
  ]);
  $summary[] = $this
    ->t('Z-index offset: @z_index_offset', [
    '@z_index_offset' => !empty($this
      ->getSetting('z_index_offset')) ? $this
      ->getSetting('z_index_offset') : $this
      ->t('None'),
  ]);
  return $summary;
}