public function DatetimeElementFormTest::buildForm in Drupal 10
Same name and namespace in other branches
- 8 core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::buildForm()
- 9 core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php \Drupal\KernelTests\Core\Datetime\DatetimeElementFormTest::buildForm()
Form constructor.
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 The form structure.
Overrides FormInterface::buildForm
File
- core/
tests/ Drupal/ KernelTests/ Core/ Datetime/ DatetimeElementFormTest.php, line 85
Class
- DatetimeElementFormTest
- Tests DatetimeElement functionality.
Namespace
Drupal\KernelTests\Core\DatetimeCode
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;
}