Loading
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_classesand appends a#pre_rendercallback.- 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
BlockClassContentAttributesTestwith a test block (block_class_testmodule) 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_COREis a constraint like~10.6.0, so the attributes were never removed) and replaced the per filesedcommands with afindloop.
Testing
ddev exec vendor/bin/phpunit web/modules/contrib/block_class/tests- Pipeline: https://git.drupalcode.org/issue/block_class-3641904/-/pipelines/1070283 (all required jobs pass).