fac3c1787d4e194a2771c6324af5bb4f6362f131
[yaffs-website] / web / modules / contrib / paragraphs / src / Form / ParagraphsTypeDeleteConfirm.php
1 <?php
2
3 namespace Drupal\paragraphs\Form;
4
5 use Drupal\Core\Entity\Query\QueryFactory;
6 use Drupal\Core\Entity\EntityDeleteForm;
7 use Drupal\Core\Form\FormStateInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Provides a form for Paragraphs type deletion.
12  */
13 class ParagraphsTypeDeleteConfirm extends EntityDeleteForm {
14
15   /**
16    * The query factory to create entity queries.
17    *
18    * @var \Drupal\Core\Entity\Query\QueryFactory
19    */
20   protected $queryFactory;
21
22   /**
23    * Constructs a new ParagraphsTypeDeleteConfirm object.
24    *
25    * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
26    *   The entity query object.
27    */
28   public function __construct(QueryFactory $query_factory) {
29     $this->queryFactory = $query_factory;
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public static function create(ContainerInterface $container) {
36     return new static(
37       $container->get('entity.query')
38     );
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function buildForm(array $form, FormStateInterface $form_state) {
45     $num_paragraphs = $this->queryFactory->get('paragraph')
46       ->condition('type', $this->entity->id())
47       ->count()
48       ->execute();
49     if ($num_paragraphs) {
50       $caption = '<p>' . $this->formatPlural($num_paragraphs, '%type Paragraphs type is used by 1 piece of content on your site. You can not remove this %type Paragraphs type until you have removed all from the content.', '%type Paragraphs type is used by @count pieces of content on your site. You may not remove %type Paragraphs type until you have removed all from the content.', ['%type' => $this->entity->label()]) . '</p>';
51       $form['#title'] = $this->getQuestion();
52       $form['description'] = ['#markup' => $caption];
53       return $form;
54     }
55
56     return parent::buildForm($form, $form_state);
57   }
58
59 }