You are here

public function EmailConfirmerResponseForm::buildForm in Email confirmer 8

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

File

src/Form/EmailConfirmerResponseForm.php, line 57

Class

EmailConfirmerResponseForm
Email confirmation response form.

Namespace

Drupal\email_confirmer\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Skip the response form and positively confirm the confirmation according
  // to the settings.
  if ($this
    ->config('email_confirmer.settings')
    ->get('confirmation_response.skip_confirmation_form')) {
    return $this
      ->skipConfirmationForm($form_state);
  }

  // Build the response form.
  $form = parent::buildForm($form, $form_state);
  unset($form['#process']);
  unset($form['#after_build']);

  // No cancel option needed.
  unset($form['actions']['cancel']);
  if ($this
    ->getEntity()
    ->isPending()) {
    $form['cancel'] = [
      '#type' => 'radios',
      '#default_value' => 0,
      '#options' => [
        0 => $this
          ->t('Confirm'),
        1 => $this
          ->t('Cancel'),
      ],
    ];
  }
  return $form;
}