Problem/Motivation
EntityReference field items already do save NEW entities (see \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::preSave). Let's make them save non-new entities too.
This can help modules like InlineEntityForm and Paragraphs / EntityReferenceRevisions.
Proposed resolution
Variant "Field item does it"
* Add sth like EntityReferenceItem::setNeedsSave(TRUE) that triggers the new behavior.
* In a followup, default needsSave to isDirty from #2862574: Add ability to track an entity object's dirty fields (and see if it has changed) once that lands.
Variant "Referenced entity does it" @Berdir #3)
* Take the EntityNeedsSaveInterface that Paragraphs implents, and make (Content?)EntityBase implement it
* In a followup, default needsSave to isDirty from #2862574: Add ability to track an entity object's dirty fields (and see if it has changed) once that lands.
Remaining tasks
* Figure out the best approach
Comments
Comment #2
geek-merlinComment #3
berdirERR supports a NeedsSaveInterface (or something like that) that paragraphs uses, then it's up to the target entity type to support that. That made more sense to me when implementing it there.
Comment #4
geek-merlin@Berdir Thanks for the quick reply!
Now that you write, it i remember this, and that you made paragraphs implement it. While the above proposes that the field item implements it. I also remember that fago implemented a similar entity-needs-save for D7 rules.
Interesting! Do you remember details why you favored that approach? (I see up- and down-sides for both)
In any case, i added it to the IS.
Comment #10
plachI implemented more or less the same feature at #3490274: Allow to re-save existing referenced entity before being pointed to this one, I think we can close this as a duplicate :)
Comment #11
plach