By joachim on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
11.6.x
Introduced in version:
11.6.0
Issue links:
Description:
Entities which are bundles of another entity type should not be deleted if there are entities of that bundle. For example, the 'article' node type entity should not be deleted if there are any nodes of type 'article'.
The new entity delete form class \Drupal\Core\Entity\BundleEntityDeleteForm provides a check for this. To use it, add the following to the definition of any custom bundle entity types:
// In the bundle entity attribute handlers array:
'form' => [
'add' => MyBundleEntityForm::class,
'edit' => MyBundleEntityForm::class,
'delete' => BundleEntityDeleteForm::class,
],
Bundle entity types which require additional logic to prevent the deletion of entities may subclass \Drupal\Core\Entity\BundleEntityDeleteForm and override the method getReasonsToPreventDeletion(). For an example, see \Drupal\comment\Form\CommentTypeDeleteForm.
Impacts:
Module developers