You are here

public function TransactionTypeDeleteForm::buildForm in Transaction 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/TransactionTypeDeleteForm.php, line 17

Class

TransactionTypeDeleteForm
Builds the form to delete transaction type entities.

Namespace

Drupal\transaction\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $transaction_count = $this->entityTypeManager
    ->getStorage('transaction')
    ->getQuery()
    ->condition('type', $this->entity
    ->id())
    ->count()
    ->execute();
  if ($transaction_count) {
    $form['#title'] = $this
      ->getQuestion();
    $caption = '<p>' . $this
      ->formatPlural($transaction_count, 'There is 1 transaction of type %type that prevents it from being deleted.', 'There are @count transactions of type %type that prevents it from being deleted.', [
      '%type' => $this->entity
        ->label(),
    ]) . '</p>';
    $form['description'] = [
      '#markup' => $caption,
    ];
    return $form;
  }
  return parent::buildForm($form, $form_state);
}