Issue #3641904: Block classes added in hook_block_view_alter() prevent content attributes/classes from being merged (Views exposed forms lose views-exposed-form)

Fixes the loss of the classes and attributes provided by the block content when a block has classes configured with Block Class (e.g. Views exposed filter blocks losing views-exposed-form, bef-exposed-form).

Issue: https://www.drupal.org/i/3641904

Cause

Since 3.1.0 (#3590322) the classes are added to #attributes in hook_block_view_alter(). Core's BlockViewBuilder::preRender() then merges the attributes of the block content (#attributes / #wrapper_attributes) with a shallow union (+=). As class is already set, the class values of the block content are discarded and removed from the content.

Changes

  • hook_block_view_alter() keeps the cleaned classes in #block_class_classes and appends a #pre_render callback.
  • New BlockClassPreRender (TrustedCallbackInterface) merges the classes into #attributes['class'] after core has processed the block content. The block entity is not loaded again.
  • New kernel test BlockClassContentAttributesTest with a test block (block_class_test module) for both #wrapper_attributes (core 11.4+) and #attributes. It fails without the fix.
  • .gitlab-ci.yml (phpstan (previous major)): fixed the Drupal 10 detection (DRUPAL_CORE is a constraint like ~10.6.0, so the attributes were never removed) and replaced the per file sed commands with a find loop.

Testing

Merge request reports

Loading
Loading