Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There is a logic that saves correct fields data for current revision on update:
// Field API always saves as default revision, so if the revision saved
// not default we have to restore the field values of the default
// now by invoking field_attach_update() once again.
if ($this->revisionKey && !$entity->{$this->defaultRevisionKey} && !empty($this->entityInfo['fieldable'])) {
field_attach_update($this->entityType, $entity->original);
}
But it should be executed before hook_entity_update(). Otherwise we have wrong revision data.
Comment | File | Size | Author |
---|---|---|---|
#1 | entity_field_revision-2379821.patch | 1.66 KB | a.milkovsky |
Comments
Comment #1
a.milkovskyHere is the patch to execute field_attach_update() earlier.
Comment #2
fagoyeah, the problem with the existing code is that during hook_entity_update() the wrong data is saved. Thus, if a module load the entity again during this hook, it gets the wrong data. Moving that code to invoke() solves this problem as it fixes the written data before any other module can load it again.
Comment #3
ongdesign CreditAttribution: ongdesign commentedWhen I test this using Bean by creating a non-default revision, I get some broken behavior, as follows:
Before this patch, the behavior was that the Revision B's image field was not populated (which was clearly broken behavior). Revision A was still (correctly) displayed when viewing the block.
After the patch, Revision B's image field is populated, as is Revision A's, but now Revision B, while still not set to "active", is the one displayed upon viewing the block. Additionally, if I set Revision B to active, then set Revision A to active, the image gets deleted from Revision B.
Hope this makes sense...