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
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 3294474_fix_usage_of_not_existing_blocks.patch | 621 bytes | krishna mishra |
| #16 | fix_problem_with_usage_of_not_existing_blocks.patch | 607 bytes | olegrymar |
| #12 | 3294474-12-imported-lb-settings.diff | 683 bytes | sanduhrs |
Issue fork drupal-3294474
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
Comment #2
idiaz.ronceroI'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.
Comment #3
larowlanI 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
Comment #4
longwaveWe 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.
Comment #5
idiaz.ronceroComment #6
akalam commentedPatch 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
Comment #7
akalam commentedComment #9
dave reidThis 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:
Comment #12
sanduhrsAdding a patch to prevent the fatal.
Comment #14
olegrymar commentedThe 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!
Comment #15
olegrymar commentedComment #16
olegrymar commentedComment #17
olegrymar commentedComment #18
smustgrave commentedShould use MRs now vs patches as DrupalCi is shutting down.
But will need a test case to show the problem as well please
Comment #19
krishna mishra commentedAdded latest patch compatible with 10.x.
Comment #20
olegrymar commentedPlease review.
Comment #21
smustgrave commentedMR appears to be against 9.5 but should be 11.x
Appears to be missing test coverage
Comment #24
mrinalini9 commentedCreated MR against 11.x.
Still test needs to be added.
Comment #25
ben.hamelinJust noting that the patch for #19 worked fine for us on 10.5. Thank you!