Problem/Motivation
If a block returns a renderable array and the array has direct attibutes they will be "stolen" from the original content and applied to the block itself.
For example a if a block returns something like this:
array(
'#attributes' => array(
'class' => array(
'foo-bar'
),
'data-test' => 'This is just a test'
),
'#markup' => 'This is block content'
);
The rendered HTML will be:
<div id="block-foobartest" class="foo-bar" data-test="This is just a test">
This is block content.
</div>
instead of:
<div id="block-foobartest">
<div class="content foo-bar" data-test="This is just a test">
This is block content.
</div>
</div>
This is especially bad for blocks that represent forms since none of the form attributes is preserved.
Steps to reproduce
From #10:
- Install the Standard profile.
- Add the Search Form block to a region on the page, somewhere it isn't likely to be given special theming. It's already in the Secondary Menu and while it does exhibit the bug there it's harder to tell due to alterations that are made.
- Visit the site front page.
- Inspect the block's HTML.
Expected result
The form contained in the block should have the attribute drupal-data-selector="search-block-form-###"
.
Actual result
The block wrapping the form has the expected attribute.
Proposed resolution
Update BlockViewBuilder
so that it applies the #wrapper_attributes
from a block's content render array to the outer block wrapper instead of the content's #attributes
.
Remaining tasks
- Make certain this change doesn't break anything else.
- Review