You are here

public function BootstrapDatepickerBase::getCommonElementSettings in Bootstrap Datepicker 8

Return array of field settings.

Return value

array Formatted array of all available settings.

1 call to BootstrapDatepickerBase::getCommonElementSettings()
BootstrapDateWidget::formElement in src/Plugin/Field/FieldWidget/BootstrapDateWidget.php
Returns the form for a single field widget.

File

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

Class

BootstrapDatepickerBase
Base class for SingleDateTime widget types.

Namespace

Drupal\bootstrap_datepicker\Plugin\Field\FieldWidget

Code

public function getCommonElementSettings() {
  $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[] = $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[] = $value - 1;
    }
  }
  $days_of_week_highlighted = '[' . implode(',', $days_of_week_highlighted) . ']';
  $selected_end_date = '';
  if ($this
    ->getSetting('end_date_selection') == 'date') {

    // Javascript library doesn't understand date format Y-m-d.
    if (!empty($this
      ->getSetting('end_date'))) {
      $new_end_date = new DrupalDateTime($this
        ->getSetting('end_date'));
      $selected_end_date = $new_end_date
        ->format('d-m-Y');
    }
  }
  elseif ($this
    ->getSetting('end_date_selection') == 'timedelta') {
    $selected_end_date = $this
      ->getSetting('end_date_timedelta');
  }
  $selected_start_date = '';
  if ($this
    ->getSetting('start_date_selection') == 'date') {
    if (!empty($this
      ->getSetting('start_date'))) {
      $new_start_date = new DrupalDateTime($this
        ->getSetting('start_date'));
      $selected_start_date = $new_start_date
        ->format('d-m-Y');
    }
  }
  elseif ($this
    ->getSetting('start_date_selection') == 'timedelta') {
    $selected_start_date = $this
      ->getSetting('start_date_timedelta');
  }
  return [
    '#assume_nearby_year' => $this
      ->getSetting('assume_nearby_year'),
    '#autoclose' => $this
      ->getSetting('autoclose'),
    '#container' => $this
      ->getSetting('container'),
    '#calendar_weeks' => $this
      ->getSetting('calendar_weeks'),
    '#clear_btn' => $this
      ->getSetting('clear_btn'),
    '#days_of_week_disabled' => $days_of_week_disabled,
    '#mask' => $this
      ->getSetting('mask'),
    '#datetimepicker_theme' => $this
      ->getSetting('datetimepicker_theme'),
    '#days_of_week_highlighted' => $days_of_week_highlighted,
    '#dates_disabled' => $this
      ->getSetting('dates_disabled'),
    '#disable_touch_keyboard' => $this
      ->getSetting('disable_touch_keyboard'),
    '#enable_on_readonly' => $this
      ->getSetting('enable_on_readonly'),
    '#end_date' => $selected_end_date,
    '#force_parse' => $this
      ->getSetting('force_parse'),
    '#format' => $this
      ->getSetting('format'),
    '#immediate_updates' => $this
      ->getSetting('immediate_updates'),
    '#keep_empty_values' => $this
      ->getSetting('keep_empty_values'),
    '#keyboard_navigation' => $this
      ->getSetting('keyboard_navigation'),
    '#language' => $this
      ->getSetting('language'),
    '#min_view_mode' => $this
      ->getSetting('min_view_mode'),
    '#max_view_mode' => $this
      ->getSetting('max_view_mode'),
    '#multidate' => $this
      ->getSetting('multidate'),
    '#multidate_separator' => $this
      ->getSetting('multidate_separator'),
    '#orientation' => $this
      ->getSetting('orientation'),
    '#rtl' => $this
      ->getSetting('rtl'),
    '#show_on_focus' => $this
      ->getSetting('show_on_focus'),
    '#show_week_days' => $this
      ->getSetting('show_week_days'),
    '#start_date' => $selected_start_date,
    '#start_view' => $this
      ->getSetting('start_view'),
    '#datepicker_title' => $this
      ->getSetting('title'),
    '#today_btn' => $this
      ->getSetting('today_btn'),
    '#toggle_active' => $this
      ->getSetting('toggle_active'),
    '#today_highlight' => $this
      ->getSetting('today_highlight'),
    '#update_view_date' => $this
      ->getSetting('update_view_date'),
    '#week_start' => $this
      ->getSetting('week_start'),
    '#z_index_offset' => $this
      ->getSetting('z_index_offset'),
  ];
}