Problem/Motivation

Running drush migrate-default-content:export-migrations fails with a Symfony YAML dump exception when content includes Layout Builder overrides. The export payload contains objects (e.g., Section /
SectionComponent), which the YAML dumper refuses to serialize. This prevents migrate_default_content from generating migration YAML for content that uses Layout Builder.

Steps to reproduce

  1. Create a content type with Layout Builder enabled and allow overrides.
  2. Create a node with Layout Builder overrides (layout + components).
  3. Export default content (or have YAML files with layout_builder__layout data).
  4. Run: drush migrate-default-content:export-migrations

Actual result

Export fails with:

Drupal\Component\Serialization\Exception\InvalidDataTypeException
Object support when dumping a YAML file has been disabled.

Stack trace points to MigrateDefaultContentCommands::writeMigrations() calling Yaml::encode() on the generated migration array.

Expected result

Export should succeed and generate migration YAML, including layout data, without attempting to serialize PHP objects.

Analysis

The migration generator currently injects a SourcePluginInterface object into the migration definition for layout fields:

  'process' => [
    'layout_builder__layout' => [
      ['plugin' => 'layout_array_to_layout_section', 'migration' => $migration],
    ],
  ],

This object is not YAML-serializable. Additionally, Layout Builder values can still include Section / SectionComponent objects during export. Symfony YAML in core throws on any object.

Proposed resolution

  1. Normalize Layout Builder objects to arrays before YAML encoding in the export command.
  2. Remove the object reference from the generated migration definition (it is not used by the process plugin, which receives the Migration instance via DI).
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ramil g created an issue. See original summary.

joelpittet’s picture

Status: Active » Needs review
Related issues: +#3160146: Add a Normalizer and Denormalizer to support Layout Builder

I will let others review, but my first (hot) take is the MR might be normalizing more than it needs to solve the problem, though I have seen it fix the issue so thanks for posting @ramil g a fix!

Similar problem here #3160146: Add a Normalizer and Denormalizer to support Layout Builder and a similar issue here too #3524169: Graceful handling of serialization failures during export