Problem/Motivation
BlockContent::delete is not guaranteed to be called as its just a wrapper to Storage::delete
Steps to reproduce
Call \Drupal::entityTypeManager()->getStorage('block_content')->delete($some_entities)
and notice that BlockContent::delete is not called.
Proposed resolution
Move the logic from BlockContent::delete to BlockContent::postDelete
Remaining tasks
Move the logic
User interface changes
API changes
Data model changes
Release notes snippet
entity_delete_multiple() calls $storage_controller->delete($entities) directly.
So any code present in the EntityClass::delete() method is never executed. Thus those two lines are not equivalent :
entity_delete_multiple('my_entity_type', array(1));
entity_load('my_entity_type', 1)->delete();
Problem : entity_delete_multiple() is marked deprecated, with the official recommendation being "use $storage_controller->delete($entities)", i.e we promote bypassing the $entity->delete() method, and deleting entities through the controller directly.
Right now, this means that entity-type-specific code for delete() should not be added in the entity type class, but in the storage controller.
However:
- nothing documents that, if that's how we want things to be, Entity::delete() should be final.
- there are definitely cases where the code would be storage-controller agnostic.
Note : The problem doesn't seem to arise for save, since we never added a generic entity_save() function.