[2.0.0-rc3] ComponentBlock & BlockSource storage issues

Created on 24 January 2025, 29 days ago

Problem/Motivation

If I create a ComponentBlock with 2 BlockSource in a component slot, I have this:

langcode: en
status: true
id: ui_suite_dsfr_alert
theme: ui_suite_dsfr
region: content
weight: 0
provider: null
plugin: 'ui_patterns:ui_suite_dsfr:alert'
settings:
  id: 'ui_patterns:ui_suite_dsfr:alert'
  label: Alert
  label_display: visible
  provider: ui_patterns_blocks
  ui_patterns:
    component_id: null
    variant_id:
      source_id: select
      source:
        value: ''
    props: {}
    slots:
      title: {  }
      message:
        sources:
          -
            source_id: block
            source:
              plugin_id: system_branding_block
              system_branding_block:
                id: system_branding_block
                label: 'Site branding'
                label_display: false
                provider: system
                use_site_logo: 0
                use_site_name: '1'
                use_site_slogan: 0
            _weight: '0'
          -
            source_id: block
            source:
              plugin_id: system_powered_by_block
              system_powered_by_block:
                id: system_powered_by_block
                label: 'Powered by Drupal'
                label_display: false
                provider: system
            _weight: '1'

There are a few issues to address.

ComponentBlock: Provider is missing

Instead of provider: null we must have provider: ui_patterns_blocks ? Am I right?

BlockSource: Settings changes are saved but not loaded

For example, I have this in the config:

use_site_logo: 0
use_site_name: '1'
use_site_slogan: 0

But i still see this rendered, so the settings must not be loaded:

use_site_logo: '1'
use_site_name: '1'
use_site_slogan: '1'

BlockSource: The source data structure is weird

Why the plugin_id is also the dynamic key of the block settings bag?

source:
  plugin_id: system_branding_block
  system_branding_block: {}

source:
  plugin_id: system_powered_by_block
  system_branding_block: {}

It is not what the block config entity is doing (for information only, we don't have to follow it):

source:
  plugin: system_powered_by_block
  settings: {}

BlockSource: We need to decide what we render

We are directly rendering BlockPluginInterface::build() instead of the "#theme" => "block" wrapper.

So, we are skipping block.html.twig template and rendering directly the content variable:

<div{{ attributes }}>
  {{ title_prefix }}
  {% if label %}
    <h2{{ title_attributes }}>{{ label }}</h2>
  {% endif %}
  {{ title_suffix }}
  {% block content %}
    {{ content }}
  {% endblock %}
</div>

This was a good decision IMHO because:

  • it is consistent with our long term vision of skipping the ThemeManager and getting rid of those kind of wrappers
  • we are not "afraid" of ignoring the modules which are altering with hook_preprocess_block because we also loading directly the plugin form and not triggering hook_block_form_block_form_alter.
    So a module like UI Styles (using both hook_preprocess_block and hook_block_form_block_form_alter) will not be compatible, but that's OK.

However:

  • why are we storing label and label_display properties which are related to the wrapper?
  • are we really sure we want to lose the features and ecosystem related to "#theme" => "block" wrapper? Let's have a last talk

Wording in code comments

In BlockSource we are mentioning "entity" instead of "plugin":

$ grep -n -r "block entity" src/Plugin/UiPatterns/Source/BlockSource.php 
135:    // Create a block entity.
201:      // Create a block entity.

Proposed resolution

Let's discuss all this and fix what need to be fixed in a single MR.

Data model changes

We hopr not, but it may be necessary. In this case, let's add a little conversion mechanism.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France pdureau Paris

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024