You are here

public function MailingListDeleteConfirmForm::buildForm in Mailing List 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/MailingListDeleteConfirmForm.php, line 45

Class

MailingListDeleteConfirmForm
Builds the form to delete mailing list entities.

Namespace

Drupal\mailing_list\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $subscription_count = $this->queryFactory
    ->get('mailing_list_subscription')
    ->condition('mailing_list', $this->entity
    ->id())
    ->count()
    ->execute();
  if ($subscription_count) {
    $caption = '<p>' . $this
      ->formatPlural($subscription_count, 'There is 1 subscription to the %type mailing list. You can not remove this mailing list until you have removed that subscription.', 'There are @count subscriptions to the %type mailing list. You can not remove this mailing list until you have removed all its subscriptions.', [
      '%type' => $this->entity
        ->label(),
    ]) . '</p>';
    $form['#title'] = $this
      ->getQuestion();
    $form['description'] = [
      '#markup' => $caption,
    ];
    $form['link'] = [
      '#type' => 'link',
      '#url' => Url::fromRoute('entity.mailing_list_subscription.collection'),
      '#title' => $this
        ->t('Manage subscriptions'),
    ];
    return $form;
  }
  return parent::buildForm($form, $form_state);
}