Imported layout builder settings fail if inline blocks are present due to missing revisions

Created on 6 July 2022, over 2 years ago
Updated 4 July 2024, 6 months ago

Problem/Motivation

When exporting the layout builder settings from a site, if inline blocks are present the resulting *.yml file will look like this:

          128118dd-d092-4a42-958e-2d686c0a1351:
            uuid: 128118dd-d092-4a42-958e-2d686c0a1351
            region: blb_region_col_1
            configuration:
              id: 'inline_block:see_more'
              label: 'See more'
              label_display: '0'
              provider: layout_builder
              view_mode: full
              context_mapping: {  }
              block_revision_id: 468 <------- REVISION ID
              block_serialized: null
            weight: 1
            additional: {  }

After importing this configuration to a different environment, layout builder fails because the block $entity
on Drupal\layout_builder\Plugin\Block::build() is null.

  public function build() {
    $block = $this->getEntity();
    return $this->entityTypeManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']);
  }

This is due to the revision_id being nonexistent on the new environment (see Drupal\layout_builder\Plugin\Block::getEntity():)

      elseif (!empty($this->configuration['block_revision_id'])) {
        $entity = $this->entityTypeManager->getStorage('block_content')->loadRevision($this->configuration['block_revision_id']);
        $this->blockContent = $entity;
      }

$entity is NULL and $this->blockContent is set to NULL as a result.

Steps to reproduce

- On an environment, create and export default layout builder settings for a given entity. Use at least one inline block.
- On a different environment, import the entity_view_display settings of the entity view mode that is using layout builder.
- Try to edit the layout: an error will occur as the inline block revision ID can't be loaded and is not created on the fly or any sanity check is in place.

Proposed resolution

I don't know much about Layout Builder inner workings, but i'm guessing that one of the following should happen:

- The revision_id shouldn't be used, and instead the block config should be exported and a brand new revision created on import.
- Inline block export on layout builder shouldn't be supported yet, sanity checks put into place to avoid fatal errors (this will result on blocks missing after an export/import)
- Somehow, inline block instances and their exact revisions should be exported alongside layout builder settings (how? i don't know)

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Layout builder 

Last updated 4 days ago

Created by

🇪🇸Spain idiaz.roncero Madrid

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024