-1

Hi I'm using the node update hook in my custom .module file in my Drupal 9 site. I have a field called field_amount. And I was wondering if I can access the old value of that field within my update hook and the new value too?

function custom_module_node_update(\Drupal\node\NodeInterface $node) {
  //access the old value of field_amount and the new value
}

1 Answer 1

1

As the docs say:

Get the original entity object from $entity->original.

In your case that would be, for example:

function custom_module_node_update(\Drupal\node\NodeInterface $node) {
  $old_field_value = $node->original->field_foo->value;
}
1
  • Thanks it works!
    – user108721
    Commented May 3, 2023 at 9:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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