function NodeTypeDeleteConfirm::buildForm

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

Overrides EntityDeleteForm::buildForm

File

core/modules/node/src/Form/NodeTypeDeleteConfirm.php, line 18

Class

NodeTypeDeleteConfirm
Provides a form for content type deletion.

Namespace

Drupal\node\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    $num_nodes = $this->entityTypeManager
        ->getStorage('node')
        ->getQuery()
        ->accessCheck(FALSE)
        ->condition('type', $this->entity
        ->id())
        ->count()
        ->execute();
    if ($num_nodes) {
        $caption = '<p>' . $this->formatPlural($num_nodes, '%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>';
        $form['#title'] = $this->getQuestion();
        $form['description'] = [
            '#markup' => $caption,
        ];
        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.