function MediaTypeDeleteConfirmForm::buildForm

Same name in other branches
  1. 9 core/modules/media/src/Form/MediaTypeDeleteConfirmForm.php \Drupal\media\Form\MediaTypeDeleteConfirmForm::buildForm()
  2. 8.9.x core/modules/media/src/Form/MediaTypeDeleteConfirmForm.php \Drupal\media\Form\MediaTypeDeleteConfirmForm::buildForm()
  3. 10 core/modules/media/src/Form/MediaTypeDeleteConfirmForm.php \Drupal\media\Form\MediaTypeDeleteConfirmForm::buildForm()

Overrides EntityDeleteForm::buildForm

File

core/modules/media/src/Form/MediaTypeDeleteConfirmForm.php, line 46

Class

MediaTypeDeleteConfirmForm
Provides a form for media type deletion.

Namespace

Drupal\media\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $num_entities = $this->entityTypeManager
        ->getStorage('media')
        ->getQuery()
        ->accessCheck(FALSE)
        ->condition('bundle', $this->entity
        ->id())
        ->count()
        ->execute();
    if ($num_entities) {
        $form['#title'] = $this->getQuestion();
        $form['description'] = [
            '#type' => 'inline_template',
            '#template' => '<p>{{ message }}</p>',
            '#context' => [
                'message' => $this->formatPlural($num_entities, '%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.', '%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.', [
                    '%type' => $this->entity
                        ->label(),
                ]),
            ],
        ];
        return $form;
    }
    return parent::buildForm($form, $form_state);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.