I want to have a computed field pull in the name and content of a field after it has been edited. I would also like the computed field to contain the content that was edited before edit (if that makes sense?). So what code do I need to find which field has been edited?

I also found this in the node_form drupal api:

// Changed must be sent to the client, for later overwrite error checking.
$form['changed'] = array(
  '#type' => 'hidden', 
  '#default_value' => isset($node->changed) ? $node->changed : NULL,

Is there a way I access this 'changed' value to check if a piece of content has been changed?

p.s. I am new to drupal and php, so stating your answer in simpler terms with more explination is greatly appreciated.


In the node form submit, you can call node_load($node->nid, NULL, TRUE) for Drupal to retrieve the original about-to-be-overwritten node, allowing you to walk the list of fields, and compare them.

I would use sha1sum(serialize($field)) to compare them, as that makes it easy to do regardless of field type.

| improve this answer | |
  • Thanks for the answer, but I have a couple questions (I am new to drupal and php (read:student)). When you say "node form submit", is that a reference to the drupal api node_form? And if I call this function in the computed field do I need to instantiate the $node variable or the $field variable. Thanks for your help. – Draedalus Jul 13 '12 at 21:38
  • 1
    If you know about hooks, then you need to implement a small custom module and use hook_form_alter to alter the node form and insert custom submit handler like so $form['#submit'][] = 'my_custom_submit_func';. And write a function named my_custom_submit_func and in that function do the node_load and compare with the values in $form_submit. Here's the Form API page, very useful – Beebee Jul 13 '12 at 23:10

If you can use hook_node_presave, you have the handy property $node->original


Which saves you making an additional node_load

| improve this answer | |
  • Hello and welcome :) Could you please provide code snippet or a bit more detailed explanation, to keep your answer useful in case your link goes down? – Mołot Jul 3 '13 at 12:25
  • This doesn't work for all fields. Many have different structures in $node->original and $node. Many also have different structures when empty than when populated. – beth Jul 22 '13 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.