I have Content type called "Items", in that i have select list field for status referencing to Taxonomy terms(delivered,hold,dispatched etc.) .
I want to store the date in some custom table when the item is "dispatched" and use that date in some other code.
Which is function in which i can write logic to store date in table? or any other way i can get dispatched date of the item?
1 Answer
You have to use one of the events described in Entity CRUD, editing, and view hooks.
One example from the documentation:
function hook_ENTITY_TYPE_update(Drupal\Core\Entity\EntityInterface $entity) {
// Update the entity's entry in a fictional table of this type of entity.
db_update('example_entity')
->fields([
'updated' => REQUEST_TIME,
])
->condition('id', $entity->id())
->execute();
}
You can get the original field values from $entity->original->status
and check if the status has changed.