Add a generic hook_entity_load()

catch - October 15, 2009 - 14:33
Project:Drupal
Version:7.x-dev
Component:base system
Category:task
Priority:critical
Assigned:Unassigned
Status:closed
Issue tags:entity, Needs Documentation, RDF
Description

Dries indicated this might be required for RDF module. Here's a patch. It has basic API docs, better examples and test coverage should be handled by RDF.

This would also disentangle entity API from field API if we wanted - since field.module could implement hook_entity_load() to do it's field attach calls. IMO modules should implement APIs defined by includes as far as possible, but that's not a task for today

AttachmentSizeStatusTest resultOperations
hook_entity_load.patch2.37 KBIdleFailed: 13624 passes, 242 fails, 622 exceptionsView details | Re-test

#1

System Message - October 15, 2009 - 14:53
Status:needs review» needs work

The last submitted patch failed testing.

#2

catch - October 15, 2009 - 15:11
Status:needs work» needs review

Fixed namespace collision with field_test_entity_load().

AttachmentSizeStatusTest resultOperations
hook_entity_load.patch8.49 KBIdleFailed: 13824 passes, 29 fails, 0 exceptionsView details | Re-test

#3

System Message - October 15, 2009 - 15:22
Status:needs review» needs work

The last submitted patch failed testing.

#4

catch - October 15, 2009 - 15:34
Status:needs work» needs review

Missed the menu loader callbac in field_test_menu().

AttachmentSizeStatusTest resultOperations
hook_entity_load.patch8.49 KBIdleFailed: 13801 passes, 29 fails, 0 exceptionsView details | Re-test

#5

System Message - October 15, 2009 - 15:52
Status:needs review» needs work

The last submitted patch failed testing.

#6

catch - October 15, 2009 - 15:58

It's sleepytime out east. Hopefully this doesn't contain any more stupidity, like not re-rolling the patch before posting the new version.

AttachmentSizeStatusTest resultOperations
hook_entity_load.patch8.82 KBIdlePassed: 13860 passes, 0 fails, 0 exceptionsView details | Re-test

#7

scor - October 16, 2009 - 00:37
Status:needs work» needs review

thanks catch, that's exactly what we need for #493030: RDF #1: core RDF module

#8

Dries - October 16, 2009 - 01:24

This looks straightforward to me, but it would be great to get some feedback from yched or bjaspan.

#9

bjaspan - October 16, 2009 - 01:48

I think this patch is a quick hack to enable a feature. But it is a feature worth having and it is a fairly safe and self-contained hack.

I don't like that we call hook_entity_load() and hook_TYPE_load(), both in module_invoke_all() mode. It's redundant; I don't see why we need hook_TYPE_load() any more. It's almost like we are trying to de-opify hook_entity_load() (before it even exists), except the very nature of the entity loader is that it acts on arbitrary types so its hooks have to specify the type. Also, why do we pass hookLoadArguments to hook_entity_load() but not hook_TYPE_load()? Seems inconsistent.

field_test_entity_load() clearly needs to be renamed due to the collision. I don't like field_test_entity_test_load() because it sounds like it is performing a test load instead of loading a test entity. I think field_test_test_entity_load() would be better, and I even re-rolled the patch that way, but that is bikeshedding that can be addressed more carefully later.

So, I think the patch is flawed, and if it were not the very last minute I'd mark it CNW. It clearly won't kill Drupal to commit it, though. What I expect is that it will be committed as is so RDF can get it in and then later we'll fix the inconsistency/redundancy with hook_entity_load() and hook_TYPE_load(), which of course will violate the rules of code freeze, but hey, it's not like there's an actual law about that.

I can't bring myself to mark it RTBC even though I fully expect it to be committed momentarily... :-)

#10

pwolanin - October 16, 2009 - 02:51
Status:needs review» reviewed & tested by the community

patch applies cleanly and the code change is minimal and includes tests. Plus ... we want RDF

#11

catch - October 16, 2009 - 03:24
Status:reviewed & tested by the community» needs review

Re-rolled for taxonomy.test hunk failure.

AttachmentSizeStatusTest resultOperations
hook_entity_load.patch8.8 KBIdlePassed: 13625 passes, 0 fails, 0 exceptionsView details | Re-test

#12

catch - October 16, 2009 - 03:43
Status:needs review» reviewed & tested by the community

rrtbc.

#13

webchick - October 16, 2009 - 03:48
Status:reviewed & tested by the community» needs work
Issue tags:+Needs Documentation

I see what Barry's saying. But in a way this is analogous to hook_form_alter() vs. hook_form_FORM_ID_alter().

And while we could go and rip out hook_node_load/user_load/etc. in favour of this, I would -1 that, to be honest. There are more than enough paradigm changes in D7. Let's wait and see how this entity stuff pans out "in the wild" before limiting people to only this most generic top-layer to interact with entities.

Committed to HEAD! This will need documenting in the upgrade guide.

#14

bjaspan - October 16, 2009 - 21:28

I retract my objection. Having hook_entity_load() and hook_TYPE_load() allows hook_TYPE_load() to called with consistently typed arguments, whereas imagine a hook_entity_load() without hook_TYPE_load() that wanted to perform entity-type-specific operations on two or more entity types that use hookLoadArguments. This hook_entity_load() would be a return to the bad old days of arguments that vary based on $op, or in this case $type.

#15

catch - October 17, 2009 - 05:17
Status:needs work» fixed

Documented in http://drupal.org/update/modules/6/7

#16

System Message - October 31, 2009 - 05:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.