Anything that is not implemented by module_invoke_all() or a close equivalent, that is, that lets all modules respond to a hook invocation with their own hook invocation, should not abuse the name hook.
Instead, all one-module only "hooks" (often called because of implementation of a true hook) should be called callbacks, labeled "Implements callback_foo()", and defined in .api.php files as callback_foo()
.
Nothing changes about their implementation. This is entirely a matter of documentation and developer understanding and expectations.
(I can't believe i couldn't find an issue for this already, please mark duplicate and link if i missed it.)
Comments
Comment #1
Damien Tournoud CreditAttribution: Damien Tournoud commentedI don't believe we have an issue for this yet, but there seems to be a general agreement on that direction (for example #400694-4: Not all hooks are hooks).
If we are changing the convention, I would also capitalize the "hook" and "callback" part, ie.
HOOK_page_alter()
andCALLBACK_insert()
.Comment #2
Crell CreditAttribution: Crell commentedI am going to say that I am mildly -1 here. Not because I like things as they are, but because anywhere that we have CALLBACK_foo() is, to me, an architecture bug to be eliminated.
That said, documenting where we're doing something incredibly stupid is a good first step, so +1 to this issue as it will help us identify all of the CALLBACK_foo() locations that we need to remove. :-)
Comment #3
tim.plunkett.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedI'm starting on trying to break out the different types of "hooks" so I can have a clearer definition in my thesis. I've posted it as a question on Drupal Answers.
Comment #5
Crell CreditAttribution: Crell commentedI tried replying there but SX apparently doesn't think I'm cool enough. In any case, Berdir's comment is essentially correct I believe. Although I would call group 2 "event hooks" and I refer to the callback garbage as either "pseudo-hooks" or "magic callbacks".
Comment #6
sun+1, even if it's only for the sake of "determining todos" ;) (coming from #983268: Use @implements Doxygen directive for hook implementations)
Comment #7
sunCross-referencing #702586: hook_field_load() and friends are not real hooks
Comment #8
catchSeems reasonable to me as well, even if it's a big todo. It's a shame we can't also document non-magic callbacks in a similar way but those are completely different too so no harm done.
Comment #9
sunThis appears to be a duplicate of #1250500: [policy adopted; patch done] Find a (standard) way to document callback signatures by now.