function CommentTypeDeleteForm::buildForm
Same name in other branches
- 8.9.x core/modules/comment/src/Form/CommentTypeDeleteForm.php \Drupal\comment\Form\CommentTypeDeleteForm::buildForm()
- 10 core/modules/comment/src/Form/CommentTypeDeleteForm.php \Drupal\comment\Form\CommentTypeDeleteForm::buildForm()
- 11.x core/modules/comment/src/Form/CommentTypeDeleteForm.php \Drupal\comment\Form\CommentTypeDeleteForm::buildForm()
Overrides EntityDeleteForm::buildForm
File
-
core/
modules/ comment/ src/ Form/ CommentTypeDeleteForm.php, line 66
Class
- CommentTypeDeleteForm
- Provides a confirmation form for deleting a comment type entity.
Namespace
Drupal\comment\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$comment_count = $this->entityTypeManager
->getStorage('comment')
->getQuery()
->accessCheck(FALSE)
->condition('comment_type', $this->entity
->id())
->count()
->execute();
$entity_type = $this->entity
->getTargetEntityTypeId();
$caption = '';
foreach (array_keys($this->commentManager
->getFields($entity_type)) as $field_name) {
/** @var \Drupal\field\FieldStorageConfigInterface $field_storage */
if (($field_storage = FieldStorageConfig::loadByName($entity_type, $field_name)) && $field_storage->getSetting('comment_type') == $this->entity
->id() && !$field_storage->isDeleted()) {
$caption .= '<p>' . $this->t('%label is used by the %field field on your site. You can not remove this comment type until you have removed the field.', [
'%label' => $this->entity
->label(),
'%field' => $field_storage->label(),
]) . '</p>';
}
}
if ($comment_count) {
$caption .= '<p>' . $this->formatPlural($comment_count, '%label is used by 1 comment on your site. You can not remove this comment type until you have removed all of the %label comments.', '%label is used by @count comments on your site. You may not remove %label until you have removed all of the %label comments.', [
'%label' => $this->entity
->label(),
]) . '</p>';
}
if ($caption) {
$form['description'] = [
'#markup' => $caption,
];
return $form;
}
else {
return parent::buildForm($form, $form_state);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.