Problem/Motivation

When placing blocks there might be problems due to their empty initial block configuration which causes rendering issues. Once a block cannot be rendered inside a slot, the whole SDC is not displayed anymore in Display builder.

Steps to reproduce

I had the following setup:

  1. Install Flag and Flag Block module
  2. Create new Flag type
  3. Try to add Flag block block into a slot

If you want to fix it you would need to adjust FlagBlock.php block plugin class and add the following lines to prevent errors while rendering:

if (empty($config['flag_block_settings'])) {
  return NULL;
}

Proposed resolution

We should not try to render a block when inserting it on the Layers island.

Comments

yannickoo created an issue. See original summary.

pdureau’s picture

To test, you must type $ composer require drupal/flag_block:2.0.0 to avoid installing Flag 5.x which is incompatible with Flag Block.

Once a block cannot be rendered inside a slot, the whole SDC is not displayed anymore in Display builder.

Maybe because of the fatal which is preventing the HTMX fragments to be updated:

AssertionError: Cannot load the "flag" entity with NULL ID. in assert() (line 266 of core/lib/Drupal/Core/Entity/EntityStorageBase.php). 

The issue is not happening when using UI Patterns without Display Builder, so this looks like the block plugins equivalent of #3549348: Fatal: Default value for props, on load for the SDC plugins.

In UI Patterns 2, we don't care much about required block settings because it was managed by the Form API:

  1. if a setting is required, we add the #required render property
  2. BlockForm can's be submitted without filling a required value
  3. So it is not possible to render a block without required props filled

In Display Builder, we can render component without subimiting BlockForm, so with a missing required value:

  • on preview panel
  • on builder panel

Proposal: as we already do with SDC, with set the default values for required settings, so we need to check the config schema of the block. Unfortunately, it will not solved this specific example because there is no config schema in the (minimally maintained) module : https://git.drupalcode.org/project/flag_block

But at least it will prevent this for the other blocks.

yannickoo’s picture

yannickoo’s picture

Thanks for checking this Pierre! I have created another issue #3571949: Create config schema for block plugin so this can be solved properly. It's good to know that Display Builder and UI Patterns are in the end just relying on properly defined plugins to make them work as expected.

yannickoo’s picture

Title: Stop rendering unconfigured blocks in Display Builder » Check config schema when attaching and rendering a block
pdureau’s picture

Beta4 has already been released.