You are here

public function RegistrationTypeDeleteForm::buildForm in RNG - Events and Registrations 8.2

Same name and namespace in other branches
  1. 8 src/Form/RegistrationTypeDeleteForm.php \Drupal\rng\Form\RegistrationTypeDeleteForm::buildForm()
  2. 3.x src/Form/RegistrationTypeDeleteForm.php \Drupal\rng\Form\RegistrationTypeDeleteForm::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 EntityConfirmFormBase::buildForm

File

src/Form/RegistrationTypeDeleteForm.php, line 40

Class

RegistrationTypeDeleteForm
Form controller for registration types.

Namespace

Drupal\rng\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $count = $this->entityManager
    ->getStorage('registration')
    ->getQuery()
    ->condition('type', $this->entity
    ->id())
    ->count()
    ->execute();
  if ($count == 0) {
    return parent::buildForm($form, $form_state);
  }
  drupal_set_message($this
    ->t('Cannot delete registration type.'), 'warning');
  $form['#title'] = $this
    ->getQuestion();
  $form['description'] = [
    '#markup' => $this
      ->formatPlural($count, 'Unable to delete registration type. It is used by @count registration.', 'Unable to delete registration type. It is used by @count registrations.'),
  ];
  return $form;
}