Generated with the help of an LLM.

Problem/Motivation

JSON:API requests, REST requests, and default content exports fail for an entity that has a Content Builder field with sections.

Steps to reproduce

  1. Add a "Content builder" field to the "Basic page" content type.
  2. Create a basic page with one section and save it.
  3. For JSON:API: install the JSON:API module and request /jsonapi/node/page/UUID, with the page's UUID.
  4. For REST: install the RESTful Web Services module, enable GET in JSON for the Content resource, and request /node/1?_format=json.
  5. For default content: run php core/scripts/drupal content:export node 1.

Steps 3-5 all fail.

The normalization error, as REST hits it:

TypeError: Drupal\serialization\Normalizer\TypedDataNormalizer::doNormalize(): Return value must be of type ArrayObject|array|string|int|float|bool|null, Drupal\layout_builder\Section returned
#0 core/modules/serialization/src/Normalizer/TypedDataNormalizer.php(36)
#1 core/modules/serialization/src/Normalizer/SchematicNormalizerTrait.php(42)
#2 vendor/symfony/serializer/Serializer.php(152)
#3 core/modules/serialization/src/Normalizer/ComplexDataNormalizer.php(47)
#4 vendor/symfony/serializer/Serializer.php(152)
#5 core/modules/serialization/src/Normalizer/ListNormalizer.php(34)
#6 vendor/symfony/serializer/Serializer.php(152)
#7 core/modules/serialization/src/Normalizer/ContentEntityNormalizer.php(35)

Default content export error:

Drupal\Component\Serialization\Exception\InvalidDataTypeException: Object support when dumping a YAML file has been disabled.
#0 core/lib/Drupal/Component/Serialization/Yaml.php(25)
#1 core/lib/Drupal/Core/DefaultContent/ExportResult.php(33)
Caused by Symfony\Component\Yaml\Exception\DumpException: Object support when dumping a YAML file has been disabled.
#0 vendor/symfony/yaml/Inline.php(146)
#1 vendor/symfony/yaml/Dumper.php(63)

A section's value is core's Section object, and JSON and YAML can't hold objects.

Proposed resolution

Normalize sections as arrays, and accept the same arrays when content is created or imported. The normalizer is registered only when the Serialization module is installed.

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
gloriaswebtech’s picture

Issue summary: View changes
gloriaswebtech’s picture

Issue summary: View changes

  • gloriaswebtech committed 595bb2fa on 1.0.x
    Issue #3637175 by gloriaswebtech: Export sections as an array
    
    Default...
gloriaswebtech’s picture

Status: Active » Fixed

Fixed in 1.0.2

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

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

Maintainers, credit people who helped resolve this issue.