You are here

public function DurationFormElementTest::buildForm in Duration Field 8.2

Same name and namespace in other branches
  1. 3.0.x tests/src/Kernel/DurationFormElementTest.php \Drupal\Tests\duration_field\Kernel\DurationFormElementTest::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

tests/src/Kernel/DurationFormElementTest.php, line 58

Class

DurationFormElementTest
Tests the 'duration' form element.

Namespace

Drupal\Tests\duration_field\Kernel

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['full_duration'] = [
    '#type' => 'duration',
  ];
  $increments = [
    '5sec' => 5,
    '1min' => 60,
    '5min' => 60 * 5,
    '15min' => 60 * 15,
    '1hr' => 60 * 60,
    '2hr' => 60 * 60 * 2,
    '7hr' => 60 * 60 * 7,
    '1day' => 60 * 60 * 24,
    '3day' => 60 * 60 * 24 * 3,
  ];
  foreach ($increments as $id => $value) {
    $form["duration_date_increment_{$id}"] = [
      '#type' => 'duration',
      '#date_increment' => $value,
    ];
  }
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => t('Submit'),
  ];
  return $form;
}