aea4ab5e835f8987dfb2851ff55f679a3c8a1e21
[yaffs-website] / web / core / modules / block_content / src / Form / BlockContentTypeDeleteForm.php
1 <?php
2
3 namespace Drupal\block_content\Form;
4
5 use Drupal\Core\Entity\EntityDeleteForm;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Provides a confirmation form for deleting a custom block type entity.
10  */
11 class BlockContentTypeDeleteForm extends EntityDeleteForm {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function buildForm(array $form, FormStateInterface $form_state) {
17     $blocks = $this->entityTypeManager->getStorage('block_content')->getQuery()
18       ->condition('type', $this->entity->id())
19       ->execute();
20     if (!empty($blocks)) {
21       $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>';
22       $form['description'] = ['#markup' => $caption];
23       return $form;
24     }
25     else {
26       return parent::buildForm($form, $form_state);
27     }
28   }
29
30 }