Generated with the help of an LLM.

Problem/Motivation

Saving a page fails when an inline block has a new entity reference that is saved with the block.

This error occurs because the block is unserialized with only the block content class allowed.

Steps to reproduce

  1. Add a Tags reference field to the "Basic block" block content type, and check "Create referenced entities if they don't already exist".
  2. Add a "Content builder" field to a content type such as "Basic page".
  3. Add content with a "One column" section and an inline "Basic block".
  4. In the Tags reference field for the Basic block, create a new tag.
  5. Save the node.

All new entities referenced in inline blocks, including Paragraphs, fail the same way.

The node form shows "The content could not be saved."

Here's the log error:

Drupal\Core\Entity\EntityStorageException: Value is not a valid entity. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 861 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
#0 core/lib/Drupal/Core/Entity/EntityBase.php(371): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\block_content\Entity\BlockContent))
#1 modules/contrib/content_builder/src/Field/ContentBuilderItemList.php(154): Drupal\Core\Entity\EntityBase->save()
#2 modules/contrib/content_builder/src/Field/ContentBuilderItemList.php(117): Drupal\content_builder\Field\ContentBuilderItemList->saveInlineBlocks()
#3 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(1076): Drupal\content_builder\Field\ContentBuilderItemList->preSave()
#4 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(1026): Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldMethod('preSave', Object(Drupal\node\Entity\Node))
#5 core/lib/Drupal/Core/Entity/EntityStorageBase.php(583): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('presave', Object(Drupal\node\Entity\Node))
#6 core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(882): Drupal\Core\Entity\EntityStorageBase->doPreSave(Object(Drupal\node\Entity\Node))
#7 core/lib/Drupal/Core/Entity/EntityStorageBase.php(537): Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object(Drupal\node\Entity\Node))
#8 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(844): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\node\Entity\Node))
#9 core/lib/Drupal/Core/Entity/EntityBase.php(371): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object(Drupal\node\Entity\Node))
#10 core/modules/node/src/Form/NodeForm.php(281): Drupal\Core\Entity\EntityBase->save()
#11 core/lib/Drupal/Core/Form/FormSubmitter.php(108): Drupal\node\Form\NodeForm->save(Array, Object(Drupal\Core\Form\FormState))

Proposed resolution

The content builder field signs the inline blocks it serializes, and upon saving, it restores signed blocks with their new entities, just as Layout Builder does.

Note: Section data from REST, JSON:API or migrations isn't signed and keeps the class limit.

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

Comments

gloriaswebtech created an issue. See original summary.

gloriaswebtech’s picture

Issue summary: View changes
gloriaswebtech’s picture

Issue summary: View changes
gloriaswebtech’s picture

Issue summary: View changes