You are here

public function DateList::form in Webform 8.5

Same name and namespace in other branches
  1. 6.x src/Plugin/WebformElement/DateList.php \Drupal\webform\Plugin\WebformElement\DateList::form()

Gets the actual configuration webform array to be built.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array An associative array contain the element's configuration webform without any default values.

Overrides DateBase::form

File

src/Plugin/WebformElement/DateList.php, line 145

Class

DateList
Provides a 'datelist' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['date']['#title'] = $this
    ->t('Date list settings');
  $form['date']['date_part_order_label'] = [
    '#type' => 'item',
    '#title' => $this
      ->t('Date part and order'),
    '#description' => $this
      ->t("Select the date parts and order that should be used in the element."),
    '#access' => TRUE,
  ];
  $form['date']['date_part_order'] = [
    '#type' => 'webform_tableselect_sort',
    '#header' => [
      'part' => 'Date part',
    ],
    '#options' => [
      'day' => [
        'part' => $this
          ->t('Days'),
      ],
      'month' => [
        'part' => $this
          ->t('Months'),
      ],
      'year' => [
        'part' => $this
          ->t('Years'),
      ],
      'hour' => [
        'part' => $this
          ->t('Hours'),
      ],
      'minute' => [
        'part' => $this
          ->t('Minutes'),
      ],
      'second' => [
        'part' => $this
          ->t('Seconds'),
      ],
      'ampm' => [
        'part' => $this
          ->t('AM/PM'),
      ],
    ],
  ];
  $form['date']['date_text_parts'] = [
    '#type' => 'checkboxes',
    '#options_display' => 'side_by_side',
    '#title' => $this
      ->t('Date text parts'),
    '#description' => $this
      ->t("Select date parts that should be presented as text fields instead of drop-down selectors."),
    '#options' => [
      'day' => $this
        ->t('Days'),
      'month' => $this
        ->t('Months'),
      'year' => $this
        ->t('Years'),
      'hour' => $this
        ->t('Hours'),
      'minute' => $this
        ->t('Minutes'),
      'second' => $this
        ->t('Seconds'),
    ],
  ];
  $form['date']['date_year_range'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Date year range'),
    '#description' => $this
      ->t("A description of the range of years to allow, like '1900:2050', '-3:+3' or '2000:+3', where the first value describes the earliest year and the second the latest year in the range.") . ' ' . $this
      ->t('Use min/max validation to define a more specific date range.'),
  ];
  $form['date']['date_year_range_reverse'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Date year range reverse'),
    '#description' => $this
      ->t('If checked date year range will be listed from max to min.'),
    '#return_type' => TRUE,
  ];
  $form['date']['date_increment'] = [
    '#type' => 'number',
    '#title' => $this
      ->t('Date increment'),
    '#description' => $this
      ->t('The increment to use for minutes and seconds'),
    '#min' => 1,
    '#size' => 4,
    '#weight' => 10,
  ];
  $form['date']['date_abbreviate'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Abbreviate month'),
    '#description' => $this
      ->t('If checked, month will be abbreviated to three letters.'),
    '#return_value' => TRUE,
  ];
  return $form;
}