You are here

public function LogRescheduleActionForm::buildForm in Log entity 2.x

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 LogActionFormBase::buildForm

File

src/Form/LogRescheduleActionForm.php, line 44

Class

LogRescheduleActionForm
Provides a log reschedule confirmation form.

Namespace

Drupal\log\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = parent::buildForm($form, $form_state);
  $form['type_of_date'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Reschedule by a relative date'),
    '#weight' => -10,
  ];
  $form['title'] = [
    '#type' => 'html_tag',
    '#tag' => 'h4',
    '#value' => $form['date']['#title'],
    '#weight' => -9,
  ];

  // Datetime fields need to be wrapped for #states to work.
  // @see https://www.drupal.org/project/drupal/issues/2419131
  $form['absolute'] = [
    '#type' => 'container',
    '#states' => [
      'visible' => [
        ':input[name="type_of_date"]' => [
          'checked' => FALSE,
        ],
      ],
    ],
  ];
  $form['absolute']['date'] = $form['date'];
  unset($form['absolute']['date']['#title']);
  $form['absolute']['date']['#required'] = FALSE;
  unset($form['date']);
  $form['relative'] = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'container-inline',
      ],
    ],
    '#states' => [
      'visible' => [
        ':input[name="type_of_date"]' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];
  $form['relative']['amount'] = [
    '#type' => 'number',
    '#size' => 4,
  ];
  $form['relative']['time'] = [
    '#type' => 'select',
    '#options' => [
      'hour' => $this
        ->t('Hours'),
      'day' => $this
        ->t('Days'),
      'week' => $this
        ->t('Weeks'),
      'month' => $this
        ->t('Months'),
      'year' => $this
        ->t('Years'),
    ],
  ];
  return $form;
}