remove $op from hook_nodeapi

justinrandell - September 27, 2008 - 15:58
Project:Drupal
Version:7.x-dev
Component:node system
Category:task
Priority:critical
Assigned:recidive
Status:closed
Description

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

AttachmentSizeStatusTest resultOperations
nodeapi.patch55.63 KBIdleFailed: Failed to apply patch.View details | Re-test

#1

justinrandell - September 27, 2008 - 16:01

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

#2

dman - September 27, 2008 - 16:19

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

#3

webchick - September 27, 2008 - 19:51

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

#4

justinrandell - September 28, 2008 - 07:00

will update this patch once HEAD is fixed.

#5

justinrandell - October 2, 2008 - 09:39
Priority:normal» critical

updated for HEAD, all tests pass.

AttachmentSizeStatusTest resultOperations
nodeapi.patch55.62 KBIdleFailed: Failed to apply patch.View details | Re-test

#6

catch - October 2, 2008 - 11:55
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.

#7

alexanderpas - October 2, 2008 - 19:32

+1 and subscribing to this one.

#8

Rob Loach - October 3, 2008 - 02:43

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

#9

chx - October 3, 2008 - 03:22

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

#10

dman - October 3, 2008 - 03:59

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

#11

Rob Loach - October 3, 2008 - 05:25

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.

#12

alexanderpas - October 3, 2008 - 06:32

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

#13

justinrandell - October 3, 2008 - 08:42

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

#14

catch - October 3, 2008 - 08:48

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.

#15

dman - October 3, 2008 - 09:20

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

#16

BioALIEN - October 5, 2008 - 01:41

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

#17

Dries - October 6, 2008 - 12:55
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.

#18

Rob Loach - October 6, 2008 - 19:53
Status:needs work» fixed

Added the update module documentation for remove $op.

#19

nedjo - October 9, 2008 - 17:20
Status:fixed» reviewed & tested by the community

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

AttachmentSizeStatusTest resultOperations
nodeapi_prepare_treanslation.patch748 bytesIdleFailed: Failed to apply patch.View details | Re-test

#20

Rob Loach - October 9, 2008 - 17:45

Yup.

#21

webchick - October 9, 2008 - 18:34
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.

#22

Rob Loach - October 9, 2008 - 19:18

#23

webchick - October 9, 2008 - 19:52

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.

#24

justinrandell - October 9, 2008 - 22:20

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

#25

justinrandell - October 10, 2008 - 01:58
Status:needs work» needs review

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.

AttachmentSizeStatusTest resultOperations
nodeapi_docs.patch8.51 KBIdleFailed: Failed to apply patch.View details | Re-test

#26

justinrandell - October 15, 2008 - 09:24
Title:remove $op from hook_nodeapi» docs for new hook_nodeapi_$op functions
Project:Drupal» Documentation
Version:7.x-dev» <none>
Component:base system» Correction/Clarification

changing title and queue.

#27

Rob Loach - October 15, 2008 - 19:03
Status:needs review» reviewed & tested by the community

This looks good to me.

#28

dman - October 15, 2008 - 19:26

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

<?php
/**
* 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.

#29

Rob Loach - October 17, 2008 - 15:29
Status:reviewed & tested by the community» needs work

Needs update to head.

#30

Rob Loach - October 17, 2008 - 15:35
Component:Correction/Clarification» Outdated
Status:needs work» needs review
  1. Updated to HEAD
  2. Removed old hook_nodeapi docs
  3. Removed function hook_nodeapi, moving old implementations into their respective hooks
AttachmentSizeStatusTest resultOperations
314244.patch10.37 KBIdleFailed: Failed to apply patch.View details | Re-test

#31

justinrandell - October 18, 2008 - 06:25

thanks Rob.

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

#32

alexanderpas - October 18, 2008 - 11:27
Status:needs review» reviewed & tested by the community

looking good, marking this as RTBC

#33

recidive - December 4, 2008 - 05:46

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.

#34

Rob Loach - December 4, 2008 - 06:47
Title:docs for new hook_nodeapi_$op functions» UNSTABLE-4 blocker: hook_nodeapi_$op Documentation Signatures
Project:Documentation» Drupal
Version:<none>» 7.x-dev
Component:Outdated» documentation
Assigned to:justinrandell» Anonymous
Status:reviewed & tested by the community» needs work

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

#35

recidive - December 4, 2008 - 16:16
Assigned to:Anonymous» recidive
Status:needs work» needs review

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.

AttachmentSizeStatusTest resultOperations
drupal_nodeapi_documentation.patch10.63 KBIdlePassed: 7435 passes, 0 fails, 0 exceptionsView details | Re-test

#36

recidive - December 4, 2008 - 16:37

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.

AttachmentSizeStatusTest resultOperations
drupal_nodeapi_documentation.patch11.47 KBIdleUnable to apply patch drupal_nodeapi_documentation_0.patchView details | Re-test

#37

recidive - December 4, 2008 - 16:43
Title:UNSTABLE-4 blocker: hook_nodeapi_$op Documentation Signatures» remove $op from hook_nodeapi
Component:documentation» node system
Status:needs review» closed

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.

#38

hass - August 23, 2009 - 12:28

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:

<?php
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;
...
}
?>

<?php
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);
  }
}
?>

#39

dman - August 23, 2009 - 12:22

<?php
function hook_node_update(&$node) {
 
hook_node_insert($node);
}
?>

Maybe.

 
 

Drupal is a registered trademark of Dries Buytaert.