function DatelistElementFormTest::buildForm

Same name in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Datetime/DatelistElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatelistElementFormTest::buildForm()
  2. 11.x core/tests/Drupal/KernelTests/Core/Datetime/DatelistElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatelistElementFormTest::buildForm()

Overrides FormInterface::buildForm

File

core/tests/Drupal/KernelTests/Core/Datetime/DatelistElementFormTest.php, line 64

Class

DatelistElementFormTest
Tests Datelist functionality.

Namespace

Drupal\KernelTests\Core\Datetime

Code

public function buildForm(array $form, FormStateInterface $form_state, string $date_callback = 'datelistDateCallbackTrusted') {
    $form['datelist_element'] = [
        '#title' => 'datelist test',
        '#type' => 'datelist',
        '#default_value' => new DrupalDateTime('2000-01-01 00:00:00'),
        '#date_part_order' => [
            'month',
            'day',
            'year',
            'hour',
            'minute',
            'ampm',
        ],
        '#date_text_parts' => [
            'year',
        ],
        '#date_year_range' => '2010:2020',
        '#date_increment' => 15,
        '#date_date_callbacks' => [
            [
                $this,
                $date_callback,
            ],
        ],
    ];
    $form['submit'] = [
        '#type' => 'submit',
        '#value' => t('Submit'),
    ];
    return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.