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

User interface changes

API changes

Data model changes

Release notes snippet

Comments

geek-merlin created an issue. See original summary.

geek-merlin’s picture

berdir’s picture

ERR 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.

geek-merlin’s picture

Issue summary: View changes

@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.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

plach’s picture

I 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 :)

plach’s picture

Status: Active » Closed (duplicate)

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.