3 namespace Drupal\media_entity\Form;
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;
11 * Provides a form for media bundle deletion.
13 class MediaBundleDeleteConfirm extends EntityDeleteForm {
16 * The query factory to create entity queries.
18 * @var \Drupal\Core\Entity\Query\QueryFactory
20 protected $queryFactory;
23 * Constructs a new MediaBundleDeleteConfirm object.
25 * @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
26 * The entity query object.
28 public function __construct(QueryFactory $query_factory) {
29 $this->queryFactory = $query_factory;
35 public static function create(ContainerInterface $container) {
37 $container->get('entity.query')
44 public function buildForm(array $form, FormStateInterface $form_state) {
45 $num_entities = $this->queryFactory->get('media')
46 ->condition('bundle', $this->entity->id())
50 $caption = '<p>' . $this->formatPlural($num_entities, '%type is used by 1 piece of content on your site. You can not remove this content type until you have removed all of the %type content.', '%type is used by @count pieces of content on your site. You may not remove %type until you have removed all of the %type content.', ['%type' => $this->entity->label()]) . '</p>';
51 $form['#title'] = $this->getQuestion();
52 $form['description'] = ['#markup' => $caption];
56 return parent::buildForm($form, $form_state);