Save paragraphs as part of a host entity save

Created on 11 December 2024, 11 days 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

Comments & Activities

  • Issue created by @alexpott
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom alexpott ๐Ÿ‡ช๐Ÿ‡บ๐ŸŒ

    One thing to think about here is what happens with entities with multiple paragraphs linking to the same entity - how many revisions are they going to get?

Production build 0.71.5 2024