Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / media / src / Form / MediaTypeDeleteConfirmForm.php
1 <?php
2
3 namespace Drupal\media\Form;
4
5 use Drupal\Core\Entity\EntityTypeManagerInterface;
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 media type deletion.
12  *
13  * @internal
14  */
15 class MediaTypeDeleteConfirmForm extends EntityDeleteForm {
16
17   /**
18    * The entity type manager.
19    *
20    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
21    */
22   protected $entityTypeManager;
23
24   /**
25    * Constructs a new MediaTypeDeleteConfirm object.
26    *
27    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
28    *   The entity type manager.
29    */
30   public function __construct(EntityTypeManagerInterface $entity_type_manager) {
31     $this->entityTypeManager = $entity_type_manager;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public static function create(ContainerInterface $container) {
38     return new static(
39       $container->get('entity_type.manager')
40     );
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function buildForm(array $form, FormStateInterface $form_state) {
47     $num_entities = $this->entityTypeManager->getStorage('media')->getQuery()
48       ->condition('bundle', $this->entity->id())
49       ->count()
50       ->execute();
51     if ($num_entities) {
52       $form['#title'] = $this->getQuestion();
53       $form['description'] = [
54         '#type' => 'inline_template',
55         '#template' => '<p>{{ message }}</p>',
56         '#context' => [
57           'message' => $this->formatPlural($num_entities,
58             '%type is used by @count media item on your site. You can not remove this media type until you have removed all of the %type media items.',
59             '%type is used by @count media items on your site. You can not remove this media type until you have removed all of the %type media items.',
60             ['%type' => $this->entity->label()]),
61         ],
62       ];
63
64       return $form;
65     }
66
67     return parent::buildForm($form, $form_state);
68   }
69
70 }