hook_user
hook_block
hook_menu
hook_nodeapi
hook_schema
hook_taxonomy

Which of these things doesn't belong? :P What on earth is a "nodeapi"?

This trips up lots of new developers and also makes our API look sloppy. IMO we should change nodeapi to node.

CommentFileSizeAuthor
#1 no_nodeapi.patch61.72 KBDavid Strauss
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

David Strauss’s picture

FileSize
61.72 KB
David Strauss’s picture

Status: Active » Needs review
mfer’s picture

Under orders to say "hell yeah".

Damien Tournoud’s picture

That's so cool (@webchick).

Crell’s picture

Status: Needs review » Reviewed & tested by the community

Amen and pass the sweet potatoes!

webchick’s picture

Status: Reviewed & tested by the community » Needs work

YAY!!! :D This patch powered by delicious melted ice cream.

Needs documenting.

David Strauss’s picture

Here's what should be added to http://drupal.org/node/224333

<h3 id="replace_hook_nodeapi_op_with_hook_node_op">Replace hook_nodeapi_$op() with hook_node_$op()</h3>
<a href="http://drupal.org/node/383066">(issue)</a>.

Drupal 6.x:
<?php
 /**
 * Implementation of hook_nodeapi_view.
  */
function blog_nodeapi_view($node, $teaser = FALSE) {
?>

Drupal 7.x:
<?php
 /**
 * Implementation of hook_node_view.
  */
function blog_node_view($node, $teaser = FALSE) {
?>
stella’s picture

Looks like you also need to add in a bit about node_invoke_nodeapi() being renamed to node_invoke_node()

Xano’s picture

I advise against this. We need to rename hooks like hook_load() to hook_node_load(), since hook names start with the name of the module that introduces them, and this patch would conflict with that.

stella’s picture

@Xano this is already committed

Xano’s picture

Status: Needs work » Active

My bad, but my advise still stands. Hook_load(), hook_form(), etc. are confusing and make the API even more sloppy. If we change them to hook_node_load(), etc., we need to think of al alternative for hook_nodeapi_X().

Damien Tournoud’s picture

@Xano: *_load(), *_form(), etc. are not really hooks as there are not called by module_invoke_all(). There are a rather dumb implementation of a strategy pattern. We need a better system for D7, for sure (probably based on some DrupalNodeType interface), renaming *_load() to *_node_load() would only add to the confusion.

See #395786: Move node-type callbacks to a proper interface.

David Strauss’s picture

Assigned: Unassigned » David Strauss
Status: Active » Needs work

With Damien's issue #395786, I'm setting this back to CNW for documentation.

webchick’s picture

Assigned: David Strauss » Unassigned
Status: Needs work » Fixed
Issue tags: +Needs documentation
webchick’s picture

Status: Fixed » Needs work

Er. I didn't mean to do that.

webchick’s picture

Also, I agree with Damien that the pseudo-hooks _load, _insert, etc. are their own thing and should be dealt with separately. Maybe by turning them OO as in #395786: Move node-type callbacks to a proper interface but that's for discussion over there. :)

But hook_user_X, hook_file_X, etc. all match the pattern of "Someone else defined this thing, and now my module wants to act on it." So hook_node_X is a good fit here.

rfay’s picture

Status: Needs work » Fixed

I added this into the docs at http://drupal.org/update/modules/6/7#hook_node_xxx

I attempted to update all previous references (now outdated) to hook_nodeapi_xxx() as well.

Status: Fixed » Closed (fixed)
Issue tags: -DX (Developer Experience), -Needs documentation

Automatically closed -- issue fixed for 2 weeks with no activity.