Problem/Motivation
It was decided that Drupal 8 will rely heavily on OOP. While the entity system does this, the only way to interact with is via procedural code. This patch intends to remove the necessity to write procedural code and opens up the possibility to make (much more) of the entity code unit testable. Other problems include a total mixup of storage independent logic with the actual storage, for example calculating the comment thread vs storing the comment thread. There are no interfaces for the storage controllers because it is entirely unclear what the specific storage needs are. The number of hooks available were totally unwieldy as well (quick, does hook_field_load fire before or after hook_field_attach_load? What about hook_field_insert and hook_field_attach_insert? Where does hook_entity_load enter into the picture?).
Proposed resolution
Hooks are out. Events are in. Storage controllers thin down and get an interface. The logic moves into a StorageSubscriber. Entity hook implementations move into an EntitySubscriber.
Remaining tasks
The patch is not yet green. It is being worked on in http://drupal.org/sandbox/chx/1857558 entitystorage branch.
User interface changes
No user interface changes.
API changes
All entity hooks die -- from hook_entity_load to hook_user_delete, all. Field attach storage hooks die. Field storage callbacks die. Entity events are born.
Related Issues
#1497374: Switch from Field-based storage to Entity-based storage
#1893772: Move entity-type specific storage logic into entity classes
Comments
Comment #1
chx CreditAttribution: chx commentedFixing title per msonnabaum's advice. Indeed most of the patch is moving code around and not writing something entirely new (although the interfaces are new) and so are the triggers (was hooks, now events).
Comment #2
andypostIs there ability to split patch on parts? to make review easy
Comment #3
andypostComment #4
xjmComment #5
chx CreditAttribution: chx commentedRemoing the increases learning curve tag. To the contrary. That's the point. Events are already used by the system. Most importantly, they are not a Drupalism.
Comment #6
Crell CreditAttribution: Crell commentedchx: If I'm understanding correctly, then, module_invoke_all('entity_load', $node) gets replaced by:
Which means injecting the dispatcher into controller/handler for entities. Am I following correctly?
If so, it sounds like it's definitely a step up, so I'd +1 that. As far as revising what events we fire, I don't know the current smörgåsbord well enough to say which are redundant... which I suppose is argument enough that we should clean those up. :-)
Comment #7
xjmNo, this definitely applies. The tag name is for the OP of the issue, not the patch. It's not my fault the tag has such a name. ;)
Comment #8
chx CreditAttribution: chx commentedComment #9
bojanz CreditAttribution: bojanz at Centarro commentedOpened a less intrusive task: #2551893: Add events for matching entity hooks. Might even be 8.0 material, but I'm not pushing it.