Save paragraphs as part of a host entity save

Created on 11 December 2024, 4 months ago

Problem/Motivation

At the moment we update paragraphs outside an update to the host entity. This resulted in some bugs that are fixed by πŸ› Updating paragraph fields is problematic Active however that fix result in an override of the \Drupal\entity_reference_revisions\Plugin\Field\FieldType\EntityReferenceRevisionsItem - which is not great.

In discussion with @Berdir and after creating πŸ“Œ Do not create new revisions if the revision ID has changed Active I think we should explore changing paragraphs as part a single update to the host entity. @Berdir pointed out that the code we're likely to want is something like:

$node->get('paragraphs')->entity->set('foo', 'bar');
$node->get('paragraphs)->entity->setNeedsSave(TRUE);
$node->setNewRevision(TRUE);
$node->save()

Obviously that'll need expanding to deal with:

  • Nested paragraphs
  • Translations
  • Multiple cardinality

Excerpt of a conversation with @Berdir:

alexpott:
I guess I might need to completely refactor the code (someone else’s) to get the host entity when changing paragraphs and go that way around. As it feels like ERR is not built to have the paragraphs changed outside of the host entity. Which is fine but the module I’m fixing doesn’t work that way.

berdir:
> As it feels like ERR is not built to have the paragraphs changed outside of the host entity.
yes, I'd say that's pretty much true. in an ideal world, there probably wouldn't be any separately entities in the first place, just hierarchic json based entity storage or something like that.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024