Problem
hook_ENTITY_TYPE_ACTION() has no prefix, which results in pseudo-random unprefixed hook names, and consequently this causes conficts. I have a local dev site with payment.module and commerce_payment.module enabled. Payment has a "payment_method" entity type and Commerce Payment has the commerce_payment_method_load() API function. When loading a payment_method entity (the one from Payment.module), Entity API fires hook_payment_method_load() and commerce_payment_method_load() is called. Apart from having completely different uses, both functions accept different arguments, which causes PHP errors to be thrown by commerce_payment_method_load().
Solution
Convert hook_ENTITY_TYPE_ACTION() to hook_entity_ENTITY_TYPE_ACTION(). This is the official behavior for hooks (to be prefixd with the name of the module defining them) and it will prevent the problem.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | entity_1549424_03.patch | 3.59 KB | xano |
| #8 | entity_1549424_02.patch | 3.59 KB | xano |
| #1 | entity_optionally_disable_entity-type_specific_hooks_01.patch | 2.16 KB | xano |
Comments
Comment #1
xanoThis patch adds an "entity-type_specific_hooks" property to hook_entity_info() that prevents entity-type specific hooks (note the property's spelling) from being fired if this property is set to FALSE in hook_entity_info(). This makes sure existing Entity API implementations will continue to function.
Comment #2
fagoEntity API provides the hooks on top of the entity-providing module, which has to own the entity-type namespace. That's fine in the case of payment_method too.
The issue you ran into is actually a generic issue with hook namespaces that might occur with modules using prefix separated by _. We cannot fix this issue in the entity api of course, still we can add an option as proposed by the patch. But let's make the option a bit nice:
What about making the hook_base_name configurable, while default to the entity type? In case the hook base name is FALSE, we do not create those hooks. Maybe just call it 'hook base' ? Existing hook-configuration keys which are specific to a certain hook should take precedence though.
Comment #3
xanoWith "hook_base_name", do you mean an existing property or is that the property I proposed with a more general name? If so, its name suggest it does more than configuring entity-specific action hooks, which may cause some confusion.
I understand, but IMHO it's a bit tricky to use another module's namespaces like Entity does. It's not the flawed feature I said it was (I apologize for that), but it certainly has its challenges.
Comment #4
xanoBump.
Comment #5
silkogelman commentedissue confirmed:
When saving a Payment method for the Payment module.
Comment #6
xanoBump. Fago, could you please advise on which solution will work for you? I'll work on a patch, but before I can start working on that I need to know which approach you believe is most suitable. Thanks! :)
Comment #7
fagoI think we should do it as following:
Let's invent this 'hook base' key and follow it.
Comment #8
xanoComment #10
xanoComment #11
silkogelman commentedQuickly tested with 7.x-1.x-dev (2012-Sep-07) in a Commerce Kickstart v2 setting.
The patch applies fine, but it keeps hitting me with the warning (maybe I am doing something wrong)
Using a 'clean' Commerce Kickstart v2 install with Payment module and Payment Commerce module.
Will retest under different circumstances at a later point in time (with a more up2date Commerce Kickstart v2 or clean Commerce install)
Comment #12
xanoThat's correct, because Payment doesn't implement this new option
yet. I'll write a patch for that later today.. The original problem has been fixed in #1819626: Entity hook collission usinghook_module_implements_alter(), which means this issue can no longer be tested using Payment.Comment #13
xanoComment #14
chris matthews commented