Changes made to node in _nodeapi hook of custom module takes no effect.

Reproduce:

Create nodeapi_test.module with:

function nodeapi_test_nodeapi($node, $op){
  switch($op){
    case "validate": $node->body .= "___ADD"; break;    
  } 
}

Enable the module in administration. Create a page.
Body is saved without addition string.

Then replace all the drupal installation (except sites directory) with files from
Drupal 4.7 RC3. Create a page again.

Page saves with "___ADD" string, as expected.

Comments

ultraBoy’s picture

Priority: Critical » Normal

My suggestions:

Are you sure about making changes when $op == 'validate'? Try another ops, such as 'load' or, more likely 'view'.
Another possibility, if this op was replaced with forms api like this one http://drupal.org/node/22218#hook_nodeapi_form

Budrick’s picture

Priority: Normal » Critical

Actually, what I need is some $node->taxonomy modification before node is saved. I want it to be saved with the changes I did on validate. $node->body is used in the above example just for simplicity.
Documentation says:

"validate": The user has just finished editing the node and is trying to preview or submit it. This hook can be used to check or even modify the node.

And the option worked fine until the 4.7 release, but now its not. It can break many modules that used the option.

Budrick’s picture

Version: 4.7.0 » 4.7.2
killes@www.drop.org’s picture

Priority: Critical » Normal

This is non-critical as it doesn't break any core functionality.

I think you should return the changed value.

Budrick’s picture

I think you should return the changed value

What do you mean?

chx’s picture

Status: Active » Closed (works as designed)

validate does not let you do that. docs update is in the works. see hook_submit.

Budrick’s picture

Documentation is still not updated: http://api.drupal.org/api/4.7/function/hook_nodeapi

"validate": The user has just finished editing the node and is trying to preview or submit it. This hook can be used to check or even modify the node. Errors should be set with form_set_error().

knugar’s picture

.... and still not updated.

After trying to use hook_nodeapi() to change $node->body during 'validate' (yes I realy want to do this, and not during 'view') in a drupal-4.7.4 module, I couldn't understand what I was doing wrong - checked and double checked the documentation... Thanks to this bug report I finaly know why i failed :-)

I think this should be corrected ASAP so others don't have to waste time on this during module development.

Budrick’s picture

Version: 4.7.2 » 5.x-dev
Component: base system » other
Status: Closed (works as designed) » Active
moshe weitzman’s picture

Title: Can`t change node in _nodeapi » better documentation of nodeapi validate/submit
Budrick’s picture

Status: Active » Closed (fixed)