1

Basically I need a way of checking whether a node field changed during some event hook...I am using hook_node_submit() but this doesn't seem to work:

$form['field_status']['und']['#value'] !== $node->field_status['und'][0]['value']

Produces equality all the time...any suggestions on which hook and how I would check equality when I know a value has changed it should fire off an email...

Alex

1
  • 1
    If you use hook_node_update() you should have access to $node->original (copy of the original object). Not sure if it's available in hook_node_submit()
    – Clive
    Aug 8 '14 at 20:42
1

As said from @Clive, the only way is to compare the value in $node with the value contained in $node->original.

As far as I can see, that value is only available in hook_node_update(), hook_node_presave() and every hook invoked from node_save() which receive the saved node as argument (but only when a node is updated), since entity_load_unchanged() is called from node_save() (which also unset $node->original before exiting). If you need it in hook_node_submit() you could simply add the following code in your implementation.

if (!empty($node->nid) && !isset($node->original)) {
  $node->original = entity_load_unchanged('node', $node->nid);
}

Since you are checking for field properties, the other, more general, hook would be hook_field_attach_submit(hook_field_attach_submit($entity_type, $entity, $form, &$form_state)). With this hook, $entity would contain the field value before the node has been edited, and $form_state contains the submitted values.

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.