function BlockContentTypeDeleteForm::buildForm

Same name and namespace in other branches
  1. 9 core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php \Drupal\block_content\Form\BlockContentTypeDeleteForm::buildForm()
  2. 10 core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php \Drupal\block_content\Form\BlockContentTypeDeleteForm::buildForm()
  3. 11.x core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php \Drupal\block_content\Form\BlockContentTypeDeleteForm::buildForm()

Overrides EntityDeleteForm::buildForm

File

core/modules/block_content/src/Form/BlockContentTypeDeleteForm.php, line 18

Class

BlockContentTypeDeleteForm
Provides a confirmation form for deleting a custom block type entity.

Namespace

Drupal\block_content\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $blocks = $this->entityTypeManager
        ->getStorage('block_content')
        ->getQuery()
        ->condition('type', $this->entity
        ->id())
        ->execute();
    if (!empty($blocks)) {
        $caption = '<p>' . $this->formatPlural(count($blocks), '%label is used by 1 custom block on your site. You can not remove this block type until you have removed all of the %label blocks.', '%label is used by @count custom blocks on your site. You may not remove %label until you have removed all of the %label custom blocks.', [
            '%label' => $this->entity
                ->label(),
        ]) . '</p>';
        $form['description'] = [
            '#markup' => $caption,
        ];
        return $form;
    }
    else {
        return parent::buildForm($form, $form_state);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.