Hi,
I need to implement some hooks in .inc file of a module.I thought implementing hooks in the .module file was the standard procedure.So as per the requirement I did some search and came across this link
http://nodesforbreakfast.com/article/2012/02/20/organize-your-module-cod...
As per the link, I implemented hook_form_alter in the .inc file of a custom module and hook_hook_info in the .module file of same module but seems like the hooks in .inc files are not being called.
The code in .module file looks like this-
mymodule_hook_info() {
$hooks['form_alter'] = array(
'group' => 'form',
);
The code in the .inc file (which is in directory includes, one level down the directory which contains the .module file) looks like-
function mymodule_form_alter(&$form, &$form_state, $form_id) {
// code here
It looks like hooks can be implemented in .inc files also, but the current approach I am using doesnt seem to be working.
Please help me what I am doing wrong.
Thanks in advance!
Comments
Comment #1
Jooblay.net commentedWhat is the status of this issue?:)
Comment #2
tjmoyer commentedThis seems to be a known issue: https://drupal.org/node/977052. A comment in the api documentation here https://api.drupal.org/comment/32908#comment-32908 says that you should use the hook_hook_function for declaring your hook function but not to rely on it to auto load the inc file. I would use module_load_include() in your module where you have your code to check for other modules implementing the hook to ensure your function is included, or where ever it seems necessary.
See the Display Suite issue relating to this and my comments here: https://drupal.org/node/1822168#comment-7515065.
Comment #3
Jooblay.net commentedLets close this ticket on the account of #2
Comment #4
fernly commentedThe simple truth is that the inc file has to be in the root of your module (on the same level of the .module file), not in the includes directory. So the group in hook_hook_info() does work as expected. Only it's not possible to define a subdirectory (in this hook).