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

Issue fork drupal-3294474

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

idiaz.roncero created an issue. See original summary.

idiaz.roncero’s picture

I'm guessing that handling the import/export of block content is way too much to handle for the config import/export system, and out of scope (there are tools also like default_content).

But, I feel that at least Drupal should 1) inform the user about this problem and 2) perform a sanity check in order to avoid fatal errors after importing.

larowlan’s picture

I think this should use entity uuid and declare a config Dependency - at least that way the missing content event is fired by the config system

longwave’s picture

We have run into this in production deploys as well, as block content isn't deployed along with config.

#3049332: Fix Log error + visual warning for missing or broken block has a patch to prevent the page from crashing entirely when this happens.

idiaz.roncero’s picture

akalam’s picture

Patch on #3180702: Export block UUID with custom Layout Builder blocks ensure block_uuid is exported and is loading the block by uuid if the block_uuid key is present. Used in combination with an content export mechanism like the structure_sync can do the trick to deploy default layouts on content types

akalam’s picture

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dave reid’s picture

This also causes the following fatal error to happen when saving a node layout override, if the default contains an inline_block that does not exist:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'block_content_id' cannot be null: INSERT INTO "inline_block_usage" ("block_content_id", "layout_entity_id", "layout_entity_type") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => 715 [:db_insert_placeholder_2] => node ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 815 of /code/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

sanduhrs made their first commit to this issue’s fork.

sanduhrs’s picture

StatusFileSize
new683 bytes

Adding a patch to prevent the fatal.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

olegrymar’s picture

The fix proposed https://www.drupal.org/files/issues/2023-11-23/3294474-12-imported-lb-se... may not work for some cases.

In general, it's very often for IDS to come as strings.

In PHP "5" !== 5. As a result, using is_int is not an option.

Please, review!

olegrymar’s picture

Status: Active » Needs review
olegrymar’s picture

olegrymar’s picture

smustgrave’s picture

Status: Needs review » Needs work

Should use MRs now vs patches as DrupalCi is shutting down.

But will need a test case to show the problem as well please

krishna mishra’s picture

Added latest patch compatible with 10.x.

olegrymar’s picture

Status: Needs work » Needs review

Please review.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

MR appears to be against 9.5 but should be 11.x

Appears to be missing test coverage

mrinalini9 made their first commit to this issue’s fork.

mrinalini9’s picture

Created MR against 11.x.
Still test needs to be added.

ben.hamelin’s picture

Just noting that the patch for #19 worked fine for us on 10.5. Thank you!

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.