1

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 1

0

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.

0

Your Answer

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

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