Pull merge.
[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  * @internal
12  */
13 class BlockContentTypeDeleteForm extends EntityDeleteForm {
14
15   /**
16    * {@inheritdoc}
17    */
18   public function buildForm(array $form, FormStateInterface $form_state) {
19     $blocks = $this->entityTypeManager->getStorage('block_content')->getQuery()
20       ->condition('type', $this->entity->id())
21       ->execute();
22     if (!empty($blocks)) {
23       $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>';
24       $form['description'] = ['#markup' => $caption];
25       return $form;
26     }
27     else {
28       return parent::buildForm($form, $form_state);
29     }
30   }
31
32 }