You are here

public function EckEntityBundleDeleteConfirm::buildForm in Entity Construction Kit (ECK) 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/EntityBundle/EckEntityBundleDeleteConfirm.php, line 68

Class

EckEntityBundleDeleteConfirm
Provides a form for ECK entity bundle deletion.

Namespace

Drupal\eck\Form\EntityBundle

Code

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

  // Check if any entity of this type already exists.
  $content_number = $this->entityTypeManager
    ->getStorage($this->entity
    ->getEntityType()
    ->getBundleOf())
    ->getQuery()
    ->accessCheck(FALSE)
    ->condition('type', $this->entity
    ->id())
    ->count()
    ->execute();
  if (!empty($content_number)) {
    $warning_message = '<p>' . $this
      ->formatPlural($content_number, '%type is used by 1 entity on your site. You can not remove this entity type until you have removed all of the %type entities.', '%type is used by @count entities on your site. You may not remove %type until you have removed all of the %type entities.', [
      '%type' => $this->entity
        ->label(),
    ]) . '</p>';
    $form['#title'] = $this
      ->getQuestion();
    $form['description'] = [
      '#markup' => $warning_message,
    ];
    return $form;
  }
  return parent::buildForm($form, $form_state);
}