same motivation as remove $op from hook_user, the time has come for $op in hooks.

CommentFileSizeAuthor
#36 drupal_nodeapi_documentation.patch11.47 KBrecidive
#35 drupal_nodeapi_documentation.patch10.63 KBrecidive
#30 314244.patch10.37 KBRobLoach
#25 nodeapi_docs.patch8.51 KBAnonymous (not verified)
#19 nodeapi_prepare_treanslation.patch748 bytesnedjo
#5 nodeapi.patch55.62 KBAnonymous (not verified)
nodeapi.patch55.63 KBAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

all tests pass, except for the upload tests that fail on a clean HEAD.

dman’s picture

O WOW.
OK, this is better code, which is cool.
This is huge. You are brave.
I don't know what else to say.

webchick’s picture

Subscribe! Let's kill $op! Kill it dead!

Anonymous’s picture

will update this patch once HEAD is fixed.

Anonymous’s picture

Priority: Normal » Critical
FileSize
55.62 KB

updated for HEAD, all tests pass.

catch’s picture

Status: Needs review » Reviewed & tested by the community

As with the user de-$op patch, there's lots here, and plenty of additional cleanup we can do after it lands. I confirmed that no tests are harmed by the patch, so let's get this in then open up many smaller follow-up issues to clean this API up more.

alexanderpas’s picture

+1 and subscribing to this one.

RobLoach’s picture

This patch is made of pure awesome.... aka subscribe.

chx’s picture

(party) (dance) :D yes yes yes please.

dman’s picture

Please don't get out the pitchforks, but would it be unreasonable to supply an old-style nodeapi stub to funnel the requests through to the new functions? I know legacy support is considered evil and all, but this is going to hit a huge number of modules, and I doubt any magic upgrade script will be able to do auto conversions. ... just so we don't fall further into another huge module upgrade lapse like we have with D6? Reduce the pain? The fix would be only a few lines.
Complain in coder.module, trigger "deprecated" notices in watchdog, but help upgraders to make it work first time. :-}

[ .dan. runs and hides ... ]

RobLoach’s picture

I believe webchick put it the best when she said "Kill it dead!". Besides, all API changes are documented at Converting 6.x modules to 7.x.

alexanderpas’s picture

not to mention.... weŕe not in freeze yet... so a big -1 (where did i left the pitchfork!) at backward compability!

This is the only time we can do this this way, and we have the oppertunity to do it good, so let's kill that bastard consistently and completely ($op that is...)

Anonymous’s picture

-1 for keeping a "compatibility layer" from me too.

i think the new shiny is worth the pain, and its consistent with The Drupal Way...

catch’s picture

Once this goes in I want to see if we can stuff $teaser and $page into the $node object (if they aren't already) and remove them from the function signatures, so we get closer to just passing a single object around the API by reference. So this is hopefully just the first step at fixing this up.

dman’s picture

Ok guys, forget I said anything. Just trying to smooth the ride. :-}

BioALIEN’s picture

-1 on keeping a "compatibility layer".

The good thing about Drupal is we don't care much about backwards compatibility. This is stated somewhere by an authoritative source so don't quote me :)

Dries’s picture

Status: Reviewed & tested by the community » Needs work

Reviewed, tested, and committed to CVS HEAD. Marking as 'code needs work' until this has been properly documented in the upgrade instructions.

RobLoach’s picture

Status: Needs work » Fixed

Added the update module documentation for remove $op.

nedjo’s picture

Status: Fixed » Reviewed & tested by the community
FileSize
748 bytes

The 'prepare translation' op was missed. Attached patch changes it to 'prepare_translation'.

RobLoach’s picture

Yup.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

Thanks. :)

Marking CNW because the docs in core.php for this are now completely and utterly wrong.

RobLoach’s picture

webchick’s picture

Yeah, I already chimed in there. I don't feel that issue is going to get solved within the next 2-3 days. But we need documentation for this change ASAP.

Anonymous’s picture

i've started on this, so if anyone else wants to chime in let me know.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
8.51 KB

here's a work in progress patch core.php.

note the function signatures - i'd appreciate some feedback. in almost all cases, i think we can eliminate the params formerly knows as $a3 and $a4.

i've created a follow-up issue to clean up the code now we're not stuck with a one-size-fits-all API.

Anonymous’s picture

Title: remove $op from hook_nodeapi » docs for new hook_nodeapi_$op functions
Project: Drupal core » Documentation
Version: 7.x-dev »
Component: base system » Correction/Clarification

changing title and queue.

RobLoach’s picture

Status: Needs review » Reviewed & tested by the community

This looks good to me.

dman’s picture

Just as an aside to those in this issue - today my eye was drawn to code in content.module

/**
 * Implementation of hook_nodeapi().
 */
function content_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  $callback = 'content_'. str_replace(' ', '_', $op);
  if (function_exists($callback)) {
    $callback($node, $a3, $a4);
  }
}

I just thought I'd like to say that it made me smile. I like nice code. That is all.

RobLoach’s picture

Status: Reviewed & tested by the community » Needs work

Needs update to head.

RobLoach’s picture

Component: Correction/Clarification » Outdated
Status: Needs work » Needs review
FileSize
10.37 KB
  1. Updated to HEAD
  2. Removed old hook_nodeapi docs
  3. Removed function hook_nodeapi, moving old implementations into their respective hooks
Anonymous’s picture

thanks Rob.

what's the way to go here? as it is, this is worth committing. who has commit access?

alexanderpas’s picture

Status: Needs review » Reviewed & tested by the community

looking good, marking this as RTBC

recidive’s picture

Hi, I've posted a list of where/how nodeapi hooks are called. I think this might help here with documenting the correct function signatures.

RobLoach’s picture

Title: docs for new hook_nodeapi_$op functions » UNSTABLE-4 blocker: hook_nodeapi_$op Documentation Signatures
Project: Documentation » Drupal core
Version: » 7.x-dev
Component: Outdated » documentation
Assigned: » Unassigned
Status: Reviewed & tested by the community » Needs work

Moved to Drupal core since node.api.php is now in.

recidive’s picture

Assigned: Unassigned » recidive
Status: Needs work » Needs review
FileSize
10.63 KB

Updated the docs to match nodeapi signatures from #319356: Update hook_nodeapi_* functions signatures and documentation.

I'm going to add some examples of hooks implementations.

recidive’s picture

Added some implementation examples. It's missing examples on hook_nodeapi_alter() and hook_nodeapi_prepare_translation() (I couldn't find module implementing those hooks in core. Also hook_nodeapi_print() doesn't exist anymore, so removing it.

recidive’s picture

Title: UNSTABLE-4 blocker: hook_nodeapi_$op Documentation Signatures » remove $op from hook_nodeapi
Component: documentation » node system
Status: Needs review » Closed (fixed)

Merged documentation to the patch in #319356: Update hook_nodeapi_* functions signatures and documentation.

Changing the title back to "remove $op from hook_nodeapi" for future reference. And closing down the issue.

hass’s picture

Could someone in here explain me how it's now possible to have one nodeapi hook doing the same for more than one hook in the same way?

Now this duplicates code n-times... in D6 it was much easier:

function linkchecker_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
      // The node is going to be published.
      if ($node->status && _linkchecker_scan_nodetype($node->type)) {
        _linkchecker_add_node_links($node);
      }
      break;
...
}
function hook_node_update($node) {
  // The node is going to be published.
  if ($node->status && _linkchecker_scan_nodetype($node->type)) {
    _linkchecker_add_node_links($node);
  }
}

function hook_node_insert($node) {
  // The node is going to be published.
  if ($node->status && _linkchecker_scan_nodetype($node->type)) {
    _linkchecker_add_node_links($node);
  }
}
dman’s picture

function hook_node_update(&$node) {
  hook_node_insert($node);
}

Maybe.

joachim’s picture