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)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Here'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.

joachim’s picture

Status: Active » Needs review

Oh yeah. Bot, I suppose.

jhodgdon’s picture

Status: Needs review » Needs work

Good 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.

joachim’s picture

I'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'?

jhodgdon’s picture

The 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.

joachim’s picture

Priority: Normal » Critical

Here'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

joachim’s picture

Status: Needs work » Needs review

Oops. Have at it, testbot!

jhodgdon’s picture

Status: Needs review » Needs work

Where's the patch?

joachim’s picture

Status: Needs work » Needs review
FileSize
35.53 KB

Oops... could've sworn I attached it.

jhodgdon’s picture

Status: Needs review » Needs work

There's some bad formatting in your patch:

+                                                                                                     /**
+ * Check installation requirements and do status reporting.
+ *
+ * This hook has two closely related uses, determined by the $phase argument:

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).

jhodgdon’s picture

And 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.

joachim’s picture

> 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.

jhodgdon’s picture

I 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).

sun.core’s picture

Priority: Critical » Normal

Not critical. Please read and understand Priority levels of Issues, thanks.

joachim’s picture

Priority: Normal » Critical

I 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.

jhodgdon’s picture

Priority: Critical » Normal

I 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.

rfay’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 633332-2.drupal.system.add-install-location.patch, failed testing.

joachim’s picture

Version: 7.x-dev » 8.x-dev

> 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.

sven.lauer’s picture

There 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.

joachim’s picture

If 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?

joachim’s picture

Update: hook_modules_uninstalled() has to go in the module file, not the install.

jhodgdon’s picture

hook_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?

sven.lauer’s picture

A 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.

sven.lauer’s picture

I 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.

sven.lauer’s picture

I 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.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

joachim’s picture

Issue summary: View changes

> (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.

jhodgdon’s picture

Do 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?

joachim’s picture

> 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.

jhodgdon’s picture

Maybe... 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).

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
larowlan’s picture

Category: Bug report » Task
Issue tags: +Bug Smash Initiative

Is this a bug or a task? Yes documentation has bugs, but is added this missing info a bug?

Optimistically changing the category.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.