You are here

public function RngContactTypeDeleteForm::buildForm in RNG Contact 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 EntityDeleteForm::buildForm

File

src/Form/RngContactTypeDeleteForm.php, line 47

Class

RngContactTypeDeleteForm
Form controller to delete a contact type.

Namespace

Drupal\rng_contact\Form

Code

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

  /** @var \Drupal\rng_contact\Entity\RngContactTypeInterface $rng_contact_type */
  $rng_contact_type =& $this->entity;
  $count = $this->entityTypeManager
    ->getStorage('rng_contact')
    ->getQuery()
    ->condition('type', $rng_contact_type
    ->id())
    ->count()
    ->execute();
  if ($count > 0) {
    drupal_set_message($this
      ->t('Cannot delete contact type.'), 'warning');
    $form['#title'] = $this
      ->getQuestion();
    $form['description'] = [
      '#markup' => $this
        ->formatPlural($count, 'Unable to delete contact type. It is used by @count contact.', 'Unable to delete contact type. It is used by @count contacts.'),
    ];
  }
  else {
    $form = parent::buildForm($form, $form_state);
  }
  return $form;
}