function DatetimeElementFormTest::buildForm

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::buildForm()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::buildForm()
  3. 11.x core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::buildForm()

Overrides FormInterface::buildForm

File

core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php, line 85

Class

DatetimeElementFormTest
Tests DatetimeElement functionality.

Namespace

Drupal\KernelTests\Core\Datetime

Code

public function buildForm(array $form, FormStateInterface $form_state, string $date_callback = 'datetimeDateCallbackTrusted', string $time_callback = 'datetimeTimeCallbackTrusted') {
    $form['datetime_element'] = [
        '#title' => 'datelist test',
        '#type' => 'datetime',
        '#default_value' => new DrupalDateTime('2000-01-01 00:00:00'),
        '#date_date_format' => 'Y-m-d',
        '#date_time_format' => 'H:i:s',
        '#date_date_element' => 'HTML Date',
        '#date_time_element' => 'HTML Time',
        '#date_increment' => 1,
        '#date_date_callbacks' => [
            [
                $this,
                $date_callback,
            ],
        ],
        '#date_time_callbacks' => [
            [
                $this,
                $time_callback,
            ],
        ],
    ];
    // Element without specifying the default value.
    $form['simple_datetime_element'] = [
        '#type' => 'datetime',
        '#date_date_format' => 'Y-m-d',
        '#date_time_format' => 'H:i:s',
        '#date_date_element' => 'HTML Date',
        '#date_time_element' => 'HTML Time',
    ];
    $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.