I realise, after quite a bit back and forth, that the groups defined by hook_hook_info() not only applies to the module that implements the hook, but to the entire system and all other modules. This is something that the documentation not communicates very well.
For instance, the Rules module implements hook_hook_info() and defines that some hooks lives in 'module.rules_defaults.inc'. Without knowing this, I had my module to implement hook_hook_info() as well and the array returned by my implementation dictated that some of the hooks invoked by Rules would live in 'module.rules.inc'.
Now, the array returned by my module would seemingly apply to all other modules as well. That is; the core would have looked for the file 'module.rules.inc' in all other modules as well as my own. However, in this case, the Rules module already implemented hook_hook_info() which led to the system to keep track of two files : 'module.rules_defaults.inc' and 'module.rules.inc'. This again is not supported, as 'group' should reference a single value and not an array. Thus, the system would not have found neither the first nor the second file due to this.
If the above, as I understand is how it works, is correct, then I'd say one should be careful with implementing hook_hook_info() as you might override something another module relies on.
I'd say at least the documentation should describe this. Any thoughts on that?
References:
How to recreate the above?
1. Install the Rules module.
2. Create your own module and have it to implement hook_hook_info() :
function yourmodule_hook_info() {
$hooks['default_rules_configuration'] = array(
'group' => 'rules_default',
);
return $hooks;
}
3. Have your module to also implement hook_hook_info_alter() and dump provided hooks:
function yourmodule_hook_info_alter(&$hooks) {
dpm($hooks);
}
Comments
Comment #1
jhodgdonI don't get what's unclear. The hook_hook_info() documentation says:
This implies to me that module A implements hook_hook_info() and defines a hook called hook_foo() in group 'bar'. Then module B may place its implementation called moduleb_foo() in either moduleb.module or moduleb.bar.inc. Module A is "exposing" the hook, and module B is "implementing" the hook. Maybe you just didn't understand the (rather standard Drupal) terminology used in this hook definition... What would make it clearer?
Comment #2
sbrattla commentedYou're probably right. My first grip approach to it was that I wanted to use it to tell Drupal how my own module is organised and where Drupal could find my hook implementations. I do realise now that the hook rather should be used by the exposing module, and not the module which implements it. In other words, I should not be using the hook in an attempt to tell Drupal where the various implemented hooks are, but rather to tell Drupal about any hooks my module exposes (if any).
It might not be the documentation's fault. I do think however that part of the confusion comes from reading about how people attempt to use the hook to organise implemented hooks into various file which the implementing module itself defines.
However, am I right when I say that this module should not be used by modules implementing hooks in an attempt to organise hooks into files which the implementing module defines, but rather should be used by the exposing modules?
Comment #3
jhodgdonYes, this hook is used by exposing modules to define groups for their hooks. If you think the documentation is unclear about this, then please re-open this issue (mark it "bug report" and "active", and if possible, suggest some better wording). Until then... I'm going to go ahead and close this one.