Problem/Motivation
BlockViewBuilder::preRender() removes data from block plugins' render arrays because of the way it nests these render arrays. A code comment documents this behavior, but all for the wrong reasons. Block plugins render (BlockPluginInterface::build()) themselves in an isolated context: they do not know where or how they will be displayed, and they shouldn't. When
BlockViewBuilder::preRender()
suddenly removes bits from blocks' render arrays, those may no longer work properly. Practical use case: a block renders itself as a link which requires a class to be styled properly. BlockViewBuilder::preRender() removes all attributes from blocks' render arrays, which includes classes, and because of that the styling no longer applies properly.
Proposed resolution
Do not mess with API-generated render arrays.
Remaining tasks
T.b.d.
User interface changes
None.
API changes
None.
Data model changes
None.
Comments
Comment #5
wim leersAFAICT the IS is referring to this in
\Drupal\block\BlockViewBuilder::preRender():A simple
git blamereveals this was done in #2171269: Handle block rendering's #attributes correctly (fixes in-place editing of custom blocks). It was discussed at length there and test coverage was provided to prove the problem was fixed.If you think this is breaking some other use case, I'm afraid that you'll have to convince us by providing a failing test of the use case that is broken by this.
Comment #6
wim leersPossibly related: #2486267: Attributes of a block content are applied to block itself.
Comment #7
wim leersComment #13
pameeela commentedThanks for reporting this issue. We rely on issue reports like this one to resolve bugs and improve Drupal core.
As part of the Bug Smash Initiative, we are triaging issues that are marked "Postponed (maintainer needs more info)".
Since there were no specific steps to reproduce the issue provided since the issue was postponed, I'm marking the issue "Closed (cannot reproduce)". If anyone can provide complete steps to reproduce the issue (starting from "Install Drupal core"), document those steps in the issue summary and set the issue status back to "Active".
Thanks!