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.
Problem/Motivation
If you are using the Entity Field API to create and save entities programatically, Entity Reference fields are picky about the order in which the entities are saved.
Example
Create an unsaved term.
Create an unsaved node and assign the term to a term ER field.
Save the term.
Save the node.
The ER field loses the value.
Proposed resolution
Make isEmpty handle this case.
Make preSave deal with it too.
Remaining tasks
Review
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#11 | interdiff.txt | 1.09 KB | larowlan |
#11 | er-save-order.4.patch | 2.54 KB | larowlan |
#9 | er-save-order.3.patch | 2.56 KB | larowlan |
#9 | interdiff.txt | 846 bytes | larowlan |
#1 | er-save-order.pass_.patch | 3.9 KB | larowlan |
Comments
Comment #1
larowlanMeh, wrong patch
Comment #2
larowlanComment #8
andypostis this related?
this needs code comment
unrelated?
Comment #9
larowlanyep unrelated hunks - fixed and added comment
Comment #10
BerdirIt looks like those two cases could be combined better then?
Can't the two checks simply be combined to a single $this->entity instanceof EntityInterface in isEmpty() and below, remove the target_id call inside hasUnsavedEntity() ?
Comment #11
larowlanThanks - great points - and thanks for explaining on irc
Comment #12
BerdirLooks good. You had to be running into this or you wouldn't have created the issue, so I guess others will too.
Comment #13
larowlanYep was working on content staging previews
Comment #16
BerdirThis was a random fail.
Comment #17
alexpottCommitted 7340fee and pushed to 8.0.x. Thanks!