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

Damien Tournoud’s picture

I 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() and CALLBACK_insert().

Crell’s picture

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

tim.plunkett’s picture

.

Anonymous’s picture

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

Crell’s picture

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

sun’s picture

+1, even if it's only for the sake of "determining todos" ;) (coming from #983268: Use @implements Doxygen directive for hook implementations)

sun’s picture

catch’s picture

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

sun’s picture

Status: Active » Closed (duplicate)