Skip to main content
4 of 4
added 5 characters in body
No Sssweat
  • 31.6k
  • 14
  • 55
  • 91

Get the before and after values of a node field

I need to compare the before save/update value with the after save/update value of a node field.

Example: There is an already existing node with the title of "Hello". I then edit the node and change the title to "World".

I need to get the before value of "Hello".

function mymodule_node_presave($node){

    $before = $node->title; 
    drupal_set_message($before, 'error');  

}


function mymodule_node_update($node){
 
    $after = $node->title; 
    drupal_set_message($after, 'warning');  

}

But I always keep getting the same value...

enter image description here

Did I just discover a drupal bug? or what? Because I've used this method in the past with user hooks and it works as expected:

function mymodule_user_presave(&$edit, $account, $category) {

     $before = $account->field_custom['und'][0]['value'];
     drupal_set_message($before, 'error'); 

}

function mymodule_user_update(&$edit, $account, $category) {

     $after = $account->field_custom['und'][0]['value'];
     drupal_set_message($after, 'warning');  

}

enter image description here

No Sssweat
  • 31.6k
  • 14
  • 55
  • 91