It would be great to store the original (before update) focal_point value to be able to use it during hook_entity_presave or hook_entity_update, like $entity and $entity->original for updated node.
For example:
$field_updated = true;
...
// Check if focal_point has been updated.
$focal_point = $entity->get('field_image')->focal_point;
if (!is_null($entity->get('field_image')->focal_point_original)) {
$field_updated = $field_updated || ($focal_point !== $entity->get('field_image')->focal_point_original);
}
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | focal_point-keep-original-focal-point-value-3102633-2.patch | 949 bytes | ugolek |
Comments
Comment #2
ugolek commentedPatch is attached.
Comment #3
bleen commentedI think this is a nice enhancement ... I'd love to hear about your specific use-case
Comment #4
ugolek commentedHi bleen, my case is pretty simple.
For example, let's call function
update_metadatawhen entity has been update.So, I use drupal_register_shutdown_function in
hook_entity_update()to register a callback that should be triggered.So, does not matter what
update_metadatafunction should do, I want to update metadata only if the image has been updated, ie file id has changed. So, it is pretty simple to do, I just check $entity and $entity->original.I also want to update metadata, if the focal point coordinates has been changed too, because it could be a different metadata after the manipulations with the same image. There is no way to catch the previous saved value from the $entity->original. So, the only way is adding a new property like
focal_point_original, that keep the old value.Does it make sense?
Comment #5
maosmurf commentedHi all,
Our use-case is: we invalidate images from CDN, but only if the focal_point has changed.
So using
MODULE_entity_update(must usehook_entity_updatebecausehook_ENTITY_TYPE_updatewould be too early, irregardless of module weight) we checkThank you for the patch!
Comment #6
bleen commented@maosmurf ... have you tested the patch and confirmed it works as advertised?
Comment #7
maosmurf commented@bleen yes, we have it in production since last week - works as advertised.
Comment #8
bleen commentedbased on #7
Comment #10
bleen commentedAwesome ... thanks for this new feature
Comment #11
bleen commented