You are here

public function BootstrapDatepickerBase::settingsForm in Bootstrap Datepicker 8

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/BootstrapDatepickerBase.php, line 100

Class

BootstrapDatepickerBase
Base class for SingleDateTime widget types.

Namespace

Drupal\bootstrap_datepicker\Plugin\Field\FieldWidget

Code

public function settingsForm(array $form, FormStateInterface $form_state) {
  $elements = [];
  $elements['assume_nearby_year'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable nearby year assumption'),
    '#description' => $this
      ->t('If true, manually-entered dates with two-digit years, such as “5/1/15”, will be parsed as “2015”, not “15”. If the year is less than 10 years in advance, the picker will use the current century, otherwise, it will use the previous one. For example “5/1/15” would parse to May 1st, 2015, but “5/1/97” would be May 1st, 1997.'),
    '#default_value' => $this
      ->getSetting('assume_nearby_year'),
    '#required' => FALSE,
  ];
  $elements['autoclose'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable autoclose'),
    '#description' => $this
      ->t('Whether or not to close the datepicker immediately when a date is selected.'),
    '#default_value' => $this
      ->getSetting('autoclose'),
    '#required' => FALSE,
    '#weight' => '-12',
  ];
  $elements['container'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Container to be appended'),
    '#description' => $this
      ->t('Appends the date picker popup to a specific element; eg: container: ‘#picker-container’ (will default to “body”)'),
    '#default_value' => $this
      ->getSetting('container'),
    '#required' => TRUE,
    '#placeholder' => 'body',
  ];
  $elements['calendar_weeks'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show calendar weeks'),
    '#description' => $this
      ->t('Whether or not to show week numbers to the left of week rows.'),
    '#default_value' => $this
      ->getSetting('calendar_weeks'),
    '#required' => FALSE,
  ];
  $elements['clear_btn'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show clear button'),
    '#description' => $this
      ->t('Whether or not to show a “Clear” button at the bottom of the datepicker to clear the input value. If “autoclose” is also set to true, this button will also close the datepicker.'),
    '#default_value' => $this
      ->getSetting('clear_btn'),
    '#required' => FALSE,
    '#weight' => '-14',
  ];
  $elements['toggle_active'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Toggel active date'),
    '#description' => $this
      ->t('When enabled, selecting the currently active date in the datepicker will unset the respective date. This option is always true when the multidate option is being used.'),
    '#default_value' => $this
      ->getSetting('toggle_active'),
    '#required' => FALSE,
    '#suffix' => '<em>(Disabled. Will be enabled for comming features.)</em>',
    '#disabled' => TRUE,
  ];
  $elements['dates_disabled'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Dates disabled'),
    '#description' => $this
      ->t('Enter a date on every new line formatted in the given date format.'),
    '#default_value' => $this
      ->getSetting('dates_disabled'),
    '#rows' => '5',
    '#required' => FALSE,
  ];
  $elements['days_of_week_disabled'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Disable specific days in week'),
    '#description' => $this
      ->t('Select days which are disabled in calendar.'),
    '#options' => [
      '1' => $this
        ->t('Sunday'),
      '2' => $this
        ->t('Monday'),
      '3' => $this
        ->t('Tuesday'),
      '4' => $this
        ->t('Wednesday'),
      '5' => $this
        ->t('Thursday'),
      '6' => $this
        ->t('Friday'),
      '7' => $this
        ->t('Saturday'),
    ],
    '#default_value' => $this
      ->getSetting('days_of_week_disabled'),
    '#required' => FALSE,
  ];
  $elements['days_of_week_highlighted'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Highlight specific days in week'),
    '#description' => $this
      ->t('Select days which are highlightin calendar.'),
    '#options' => [
      '1' => $this
        ->t('Sunday'),
      '2' => $this
        ->t('Monday'),
      '3' => $this
        ->t('Tuesday'),
      '4' => $this
        ->t('Wednesday'),
      '5' => $this
        ->t('Thursday'),
      '6' => $this
        ->t('Friday'),
      '7' => $this
        ->t('Saturday'),
    ],
    '#default_value' => $this
      ->getSetting('days_of_week_highlighted'),
    '#required' => FALSE,
  ];
  $elements['disable_touch_keyboard'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Disable touch keyboard'),
    '#description' => $this
      ->t('When enabled, no keyboard will show on mobile devices'),
    '#default_value' => $this
      ->getSetting('disable_touch_keyboard'),
    '#required' => FALSE,
  ];
  $elements['enable_on_readonly'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable on readonly'),
    '#description' => $this
      ->t('When enabled, the datepicker will also show on a readonly datepicker field.'),
    '#default_value' => $this
      ->getSetting('enable_on_readonly'),
    '#required' => FALSE,
  ];
  $elements['end_date_selection'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('End date option'),
    '#description' => $this
      ->t('The latest date that may be selected; all later dates will be disabled.'),
    '#options' => [
      'date' => $this
        ->t('Date'),
      'timedelta' => $this
        ->t('Timedelta'),
    ],
    '#default_value' => $this
      ->getSetting('end_date_selection'),
    '#required' => TRUE,
  ];
  $elements['end_date'] = [
    '#type' => 'date',
    '#title' => $this
      ->t('End date'),
    '#default_value' => $this
      ->getSetting('end_date'),
    '#states' => [
      'invisible' => [
        'select[name*="end_date_selection"]' => [
          'value' => 'timedelta',
        ],
      ],
    ],
  ];
  $elements['end_date_timedelta'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('End date timedelta'),
    '#description' => $this
      ->t('A timedelta relative to today, eg “-1d”, “+6m +1y”, etc, where valid units are “d” (day), “w” (week), “m” (month), and “y” (year). Use “0” as today. There are also aliases for the relative timedelta’s: “yesterday” equals “-1d”, “today” is equal to “+0d” and “tomorrow” is equal to “+1d”.'),
    '#default_value' => $this
      ->getSetting('end_date_timedelta'),
    '#size' => 16,
    '#maxlength' => 10,
    '#states' => [
      'invisible' => [
        'select[name*="end_date_selection"]' => [
          'value' => 'date',
        ],
      ],
    ],
  ];
  $elements['force_parse'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Force date parcing'),
    '#description' => $this
      ->t('Whether or not to force parsing of the input value when the picker is closed.'),
    '#default_value' => $this
      ->getSetting('force_parse'),
    '#required' => FALSE,
  ];
  $elements['format'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Date format'),
    '#description' => $this
      ->t('The date format, combination of d, dd, D, DD, m, mm, M, MM, yy, yyyy. For example dd/mm/yyyy'),
    '#default_value' => $this
      ->getSetting('format'),
    '#size' => 10,
    '#maxlength' => 10,
    '#required' => TRUE,
    '#patern' => '{10}',
    '#placeholder' => 'yyyy-mm-dd',
    '#weight' => '-19',
  ];
  $elements['immediate_updates'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Immediate updates'),
    '#description' => $this
      ->t('If true, selecting a year or month in the datepicker will update the input value immediately. Otherwise, only selecting a day of the month will update the input value immediately.'),
    '#default_value' => $this
      ->getSetting('immediate_updates'),
    '#required' => FALSE,
  ];
  $elements['keep_empty_values'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Keep empty values'),
    '#description' => $this
      ->t('Only effective in a range picker. If true, the selected value does not get propagated to other, currently empty, pickers in the range.'),
    '#default_value' => $this
      ->getSetting('keep_empty_values'),
    '#required' => FALSE,
  ];
  $elements['keyboard_navigation'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Keyboard navigation'),
    '#description' => $this
      ->t('Whether or not to allow date navigation by arrow keys.'),
    '#default_value' => $this
      ->getSetting('keyboard_navigation'),
    '#required' => FALSE,
  ];
  $elements['language'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Language'),
    '#description' => $this
      ->t('The <abbr title="Internet Engineering Task Force">IETF</abbr> language tag. For example <em>de</em> or <em>en-UK</em>'),
    '#default_value' => $this
      ->getSetting('language'),
    '#size' => 10,
    '#maxlength' => 2,
    '#required' => TRUE,
    '#patern' => '[a-z]{2}',
    '#placeholder' => 'en',
    '#weight' => '-18',
  ];
  $elements['max_view_mode'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Max view mode'),
    '#description' => $this
      ->t('Set a maximum limit for the view mode.'),
    '#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'),
    ],
    '#default_value' => $this
      ->getSetting('max_view_mode'),
    '#required' => FALSE,
  ];
  $elements['min_view_mode'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Min view mode'),
    '#description' => $this
      ->t('Set a minimum limit for the view mode.'),
    '#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'),
    ],
    '#default_value' => $this
      ->getSetting('min_view_mode'),
    '#required' => FALSE,
  ];
  $elements['multidate'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Multiple dates'),
    '#description' => $this
      ->t('Enable multidate picking. Each date in month view acts as a toggle button, keeping track of which dates the user has selected in order. If a number is given, the picker will limit how many dates can be selected to that number, dropping the oldest dates from the list when the number is exceeded.'),
    '#default_value' => $this
      ->getSetting('multidate'),
    '#required' => FALSE,
    '#suffix' => '<em>(Disabled. Will be enabled for comming features.)</em>',
    '#disabled' => TRUE,
  ];
  $elements['multidate_separator'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Multiple dates separator'),
    '#description' => $this
      ->t('The string that will appear between dates when generating the input’s value. When parsing the input’s value for a multidate picker, this will also be used to split the incoming string to separate multiple formatted dates; as such, it is highly recommended that you not use a string that could be a substring of a formatted date (eg, using ‘-‘ to separate dates when your format is ‘yyyy-mm-dd’).'),
    '#default_value' => $this
      ->getSetting('multidate_separator'),
    '#size' => 10,
    '#maxlength' => 1,
    '#required' => FALSE,
    '#patern' => '[^A-Za-z0-9]{1}',
    '#suffix' => '<em>(Disabled. Will be enabled for comming features.)</em>',
    '#disabled' => TRUE,
  ];
  $elements['orientation'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Orientation'),
    '#description' => $this
      ->t('“orientation” refers to the location of the picker popup’s “anchor”; you can also think of it as the location of the trigger element (input, component, etc) relative to the picker.'),
    '#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'),
    ],
    '#default_value' => $this
      ->getSetting('orientation'),
    '#required' => FALSE,
  ];
  $elements['rtl'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Languages direction'),
    '#description' => $this
      ->t('Set to true if you are using a RTL language.'),
    '#default_value' => $this
      ->getSetting('rtl'),
    '#required' => FALSE,
    '#weight' => '-17',
  ];
  $elements['show_on_focus'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show on focus'),
    '#description' => $this
      ->t('If false, the datepicker will be prevented from showing when the input field associated with it receives focus.'),
    '#default_value' => $this
      ->getSetting('show_on_focus'),
    '#required' => FALSE,
  ];
  $elements['show_week_days'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show week days'),
    '#description' => $this
      ->t('When enabled, the datepicker will append the names of the weekdays to its view.'),
    '#default_value' => $this
      ->getSetting('show_week_days'),
    '#required' => FALSE,
    '#weight' => '-16',
  ];
  $elements['start_date_selection'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Start date option'),
    '#description' => $this
      ->t('The earliest date that may be selected; all earlier dates will be disabled.'),
    '#options' => [
      'date' => $this
        ->t('Date'),
      'timedelta' => $this
        ->t('Timedelta'),
    ],
    '#default_value' => $this
      ->getSetting('start_date_selection'),
    '#required' => TRUE,
  ];
  $elements['start_date'] = [
    '#type' => 'date',
    '#title' => $this
      ->t('Start date'),
    '#default_value' => $this
      ->getSetting('start_date'),
    '#states' => [
      'invisible' => [
        'select[name*="start_date_selection"]' => [
          'value' => 'timedelta',
        ],
      ],
    ],
  ];
  $elements['start_date_timedelta'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Start date timedelta'),
    '#description' => $this
      ->t('A timedelta relative to today, eg “-1d”, “+6m +1y”, etc, where valid units are “d” (day), “w” (week), “m” (month), and “y” (year). Use “0” as today. There are also aliases for the relative timedelta’s: “yesterday” equals “-1d”, “today” is equal to “+0d” and “tomorrow” is equal to “+1d”.'),
    '#default_value' => $this
      ->getSetting('start_date_timedelta'),
    '#size' => 16,
    '#maxlength' => 10,
    '#states' => [
      'invisible' => [
        'select[name*="start_date_selection"]' => [
          'value' => 'date',
        ],
      ],
    ],
  ];
  $elements['start_view'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Start view'),
    '#description' => $this
      ->t('The view that the datepicker should show when it is opened.'),
    '#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'),
    ],
    '#default_value' => $this
      ->getSetting('start_view'),
    '#required' => FALSE,
  ];
  $elements['title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Datepicker title'),
    '#description' => $this
      ->t('A title that will appear on top of the datepicker. If empty the title will be hidden.'),
    '#default_value' => $this
      ->getSetting('title'),
    '#size' => 60,
    '#maxlength' => 128,
    '#required' => FALSE,
    '#patern' => '[a-zA-Z0-9]+',
    '#weight' => '-20',
  ];
  $elements['today_btn'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Show today button'),
    '#description' => $this
      ->t('If true, the “Today” button will move the current date into view, it will not select the current date.'),
    '#options' => [
      'FALSE' => $this
        ->t('No'),
      'TRUE' => $this
        ->t('Yes'),
      'linked' => $this
        ->t('Linked'),
    ],
    '#default_value' => $this
      ->getSetting('today_btn'),
    '#required' => FALSE,
    '#weight' => '-15',
  ];
  $elements['today_highlight'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Highlight today'),
    '#description' => $this
      ->t('When enabled, highlights the current date.'),
    '#default_value' => $this
      ->getSetting('today_highlight'),
    '#required' => FALSE,
  ];
  $elements['update_view_date'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Update view date'),
    '#default_value' => $this
      ->getSetting('update_view_date'),
    '#required' => FALSE,
  ];
  $elements['week_start'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Week start'),
    '#description' => $this
      ->t('Day of the week start.'),
    '#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'),
    ],
    '#default_value' => $this
      ->getSetting('week_start'),
    '#required' => FALSE,
    '#weight' => '-10',
  ];
  $elements['z_index_offset'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Z-index offset'),
    '#description' => $this
      ->t('The CSS z-index of the open datepicker is the maximum z-index of the input and all of its DOM ancestors plus this value'),
    '#default_value' => $this
      ->getSetting('z_index_offset'),
    '#required' => FALSE,
    '#placeholder' => 10,
  ];
  return $elements;
}