On D6, core hooks were described in several files: core.php, install.php, node.php. Hooks described in install.php were hooks that modules should implement in their MODULE.install file rather than MODULE.module.
This information has vanished in the new system of MODULE.api.php files.
For example, system.api.php has hook_cron, hook_exit and others which go in MODULE.module, but also hook_install and hook_schema, which go in the MODULE.install file.
This information should probably go in the text of the hook description.
(Though I'd really like this to be indicated in a standard way that module_builder can parse, such as an @ingroup)
Comment | File | Size | Author |
---|---|---|---|
#9 | 633332-2.drupal.system.add-install-location.patch | 35.53 KB | joachim |
#1 | 633332.drupal.system.add-install-location.patch | 2.64 KB | joachim |
Comments
Comment #1
joachim CreditAttribution: joachim commentedHere's a patch adding some @ingroups: 'hooks_file_module_install', which I am breaking down as 'hooks_file' -- declares this hook needs to go somewhere other than the module file -- then 'module_install', where due to the doxygen syntax not allowing dots, an underscore will have to do.
No idea if this requires a @defgroup too.
Comment #2
joachim CreditAttribution: joachim commentedOh yeah. Bot, I suppose.
Comment #3
jhodgdonGood point!
So the patch needs work, because definitely if you want those hooks to appear in a particular group page on api.drupal.org, you need to do a defgroup as well as ingroup.
I would also be in favor of adding a line to each of those hook docs, like:
Note that implementations of this hook belong in your module's mymodule.install file, rather than the mymodule.module file.
Comment #4
joachim CreditAttribution: joachim commentedI'm not sure the group page on api.drupal.org is necessary -- might be useful though.
My main point is a formal way of specifying where a hook goes, for things like module_builder or coder module to use.
I wonder whether the tag I used in unambiguous enough, as I think some Views hooks go in module_foo.inc files, so we can't reliably say the underscore is a dot as sometimes it could really be an underscore.
Maybe 'hooks_file_module_dot_install'?
Comment #5
jhodgdonThe problem is that if you add a tag like @ingroup abcdef, it will not be displayed on api.drupal.org at all if there is no corresponding defgroup.
Which is why I think it is best to just put some explicit text in there saying that the hook implementation belongs in file xyz.ext, rather than being cryptic by using a tag that not everyone will understand necessarily.
Comment #6
joachim CreditAttribution: joachim commentedHere's a patch that adds a defgroup.
It's scarier than it looks, as I've moved hooks around so that all the install file hooks are together at the end.
I've used the format 'hooks_file_module_dot_install' so the dot is explicit; this means we won't run into problems with contrib modules requiring files with a combination of underscores and dots and the like.
Upping this to critical, as most of these hook descriptions don't actually say that the function should be defined in module.install.
The list I've put into the group is:
hook_requirements
hook_schema
hook_schema_alter
hook_install
hook_update_N
hook_update_last_removed
hook_uninstall
hook_enable
hook_disable
Furthermore, there are hooks that I'm not sure about, such as hook_install_tasks
Comment #7
joachim CreditAttribution: joachim commentedOops. Have at it, testbot!
Comment #8
jhodgdonWhere's the patch?
Comment #9
joachim CreditAttribution: joachim commentedOops... could've sworn I attached it.
Comment #10
jhodgdonThere's some bad formatting in your patch:
I also think the name of your defgroup could be simpler... how about just install_file_hooks?
Also, to make the patch less scary, how about just defining the defgroup, leaving the hooks grouped as they currently are, and adding the @ingroup to the individual hooks (as you had it before), rather than moving them so they are all together? It seems like that would make it more certain that anyone reading the raw doc would notice that the hooks are in that group, because that file is pretty big, and they might very well not notice that @defgroup if they're looking at a particular hook doc.
Finally, have you tested your patch with the API module to verify that it correctly makes this group, and adds all the hooks to that group as well as leaving them in the plain Hooks group? Whoever marks this RTBC needs to do that (just noting this mostly as a reminder for myself).
Comment #11
jhodgdonAnd by the way, once the defgroup name is standardized, I think we can easily do this for D6 as well. Especially if it's a relatively simple patch (just adding @ingroup to a bunch of hooks, and a @defgroup to one of the hook files). But we should agree on the format in D7 first and get it committed there before fixing D6 (in the contrib repository), so that we do it exactly the same in D6 and things will link correctly on api.drupal.org.
Comment #12
joachim CreditAttribution: joachim commented> I also think the name of your defgroup could be simpler... how about just install_file_hooks?
For my own needs with module_builder, the name of the defgroup needs to be a string that can be parsed into a filename. install_file_hooks won't cut it. I appreciate that this is perhaps a specialized requirement... but there may be other advantages down the road, I imagine.
Comment #13
jhodgdonI still don't like the name, but I suppose module_builder probably wants to be general (such as Views hooks, etc. that also might need to go in different files)? So I'd be willing to live with the complicated name.
I still think it would be better to use @ingroup than to move all the hooks around in the file, though, and the formatting still needs fixing. And the patch needs to be tested with the API module, either by you or by the patch reviewer/me, to make sure it actually works (creates the topic group with the installation hooks in it).
Comment #14
sun.core CreditAttribution: sun.core commentedNot critical. Please read and understand Priority levels of Issues, thanks.
Comment #15
joachim CreditAttribution: joachim commentedI understand them perfectly: "Basically if the project (core, module, theme, etc.) can't be used as intended, then it is a critical problem. "
One intention of Drupal is that is can be extended. If you put your hook_install() in the wrong place, it doesn't work. Therefore you can't extend Drupal. QED.
Comment #16
jhodgdonI am downgrading this issue from critical to normal.
Not having the location of hooks documented on api.drupal.org will not block the release of Drupal 7.
There are two reasons:
a) Most module developers already know where hooks go.
b) It is documented in module building guides etc. in the Handbook.
I am not saying we should not fix it, but it truly is not a release blocker. I realize you feel strongly about it, but apparently you have higher priorities than supplying an acceptable patch, as do we all -- this is just not as critical as many of the issues that are of status "normal" in the Drupal issue queue.
Comment #17
rfay#9: 633332-2.drupal.system.add-install-location.patch queued for re-testing.
Comment #19
joachim CreditAttribution: joachim commented> a) Most module developers already know where hooks go.
Apparently they don't... #1306624: hook_modules_un/installed/en/disabled aren't all in the same files.
Comment #20
sven.lauer CreditAttribution: sven.lauer commentedThere is an issue here about where hooks NEED to go vs. where they SHOULD go---e.g., in D7 hook_install()-implementations work perfectly fine if placed in .module files (as those are loaded on install), but they SHOULD go in .install files, AFAIK. The only things that NEED to go into .install files is functions that need to be present on uninstall (such as hook_schema and hook_uninstall implementations).
Not sure where hook_module_enabled() implementations should go --- .module files seems sensible to me.
Comment #21
joachim CreditAttribution: joachim commentedIf we add this information in a way that's parsable, then this could be added to Coder review, and thence to project testing and project application review.
I notice that in modules/system we have both system.api.php and theme.api.php. Clearly the base part of the filename does not need to match a module name, so how about just moving the hooks that belong in the install file to install.api.php or system.install.api.php?
Comment #22
joachim CreditAttribution: joachim commentedUpdate: hook_modules_uninstalled() has to go in the module file, not the install.
Comment #23
jhodgdonhook_modules_* have to go in the module files, because these are ways for modules to respond to other modules being installed/enabled/etc.
The only ones that should go in the install file I think are:
hook_install
hook_uninstall
hook_enable
hook_disable
hook_schema
(and I am doing this from memory so I may have some of the names wrong -- did I miss any?)
Anyway, because of #1247626: hook_install/hook_uninstall doc does not specify that the implementations must live in the .install file some of these are now appropriately documented...
Can someone who is interested in this check the 8.x API site please, and see which hooks still need a note that they belong elsewhere besides in the .module file (whether they *should* or *must* be, I think we could add notes to the doc)? Because most hooks belong in the .module file, I think we should only document the exceptions, right?
Comment #24
sven.lauer CreditAttribution: sven.lauer commentedA quick rundown ("Yes" means the hook doc says where the implementation must/should go):
hook_install()
: Yes.hook_uninstall()
: Yes.hook_enable()
: No, needs a "should" comment.hook_disable()
: No, though implicit in "Perform necessary actions before module is disabled."---"should" comment needed.hook_schema()
: Yes.hook_schema_alter()
: No, needs a "should" comment (at least I THINK this is not called on uninstall, and hence could live in .module).There is, of course, still the issue of finding a parseable way to indicate that a hook should go into the install file. I rather like the idea of introducing a new file to contain .install hooks. I'd prefer MODULE_NAME.install.api.php.
(True, few modules besides system will have this file, but a general convention is useful.)
There also is
hook_field_schema()
, which does already have a note about having to be in the install file.Comment #25
sven.lauer CreditAttribution: sven.lauer commentedI opened #1309298: Document that hook_(en|dis)able implementations should live in .install files (with a patch attached) in order to add the missing info to the documentation of hook_enable() and hook_disable().
I did this in a new issue so that we can keep discussing here how this info could be provided in machine-parseable format.
I also opened #1309302: Improve hook_schema_alter() documentation., but sans patch for now, as I am not sure what the actual behavior is.
Comment #26
sven.lauer CreditAttribution: sven.lauer commentedI really think that if we want to add this information in a machine-parseable form, we have two options:
(a) Introduce a new file name scheme as suggested in #21.
(b) Introduce a new doxygen directive specifically for this purpose, as @ingroup will not work with proper file names / file name patterns.
(a) would be more conservative, in a way, while (b) would be more general.
Comment #28
joachim CreditAttribution: joachim commented> (a) Introduce a new file name scheme as suggested in #21.
The problem with that is with something like hook_views_data(), which goes in a .views.inc file. Views hooks are already documented in views.api.php, so we can't add a new file to indicate the destination file.
So I think it needs to be a new doxygen directive.
Comment #29
jhodgdonDo you have a suggestion of what this directive would look like?
Also... aside from the few remaining hooks in 8 that go into the .install file, there is hook_hook_info() that can be parsed to see what hooks go into special include files:
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Extension!module....
So it seems like module builder could parse those implementations, and have a very short list of hooks that belong in the .install file. Right?
Comment #30
joachim CreditAttribution: joachim commented> So it seems like module builder could parse those implementations, and have a very short list of hooks that belong in the .install file. Right?
Indeed, that's what it does.
However, I do feel it would be better to have hook location files documented in a formal manner. As mentioned above, things like Coder review could check for that more easily too.
Comment #31
jhodgdonMaybe... My feeling is that documentation that has to be maintained separate from code is unlikely to be maintained. We have hook_hook_info(), which is code, which determines where hooks should be. I don't think we should also enforce a documentation standard that provides the same information. Having the same information in two places is just asking for it to be inconsistent.
For the hooks that should be in the .install file... they are few... and if they are in a .module file, it is not a major problem (I think they will still work, it's just a bit less efficient).
Comment #41
larowlanIs this a bug or a task? Yes documentation has bugs, but is added this missing info a bug?
Optimistically changing the category.