Following #1535868: Convert all blocks into plugins, menu blocks (e.g., the Tools block installed by the Standard profile) are rendered with <li> items not wrapped by a <ul>, because _block_get_renderable_block() does $element += $build;, but $element already has a #theme_wrappers for 'block', so $build's #theme_wrappers of 'menu_tree__tools' doesn't get incorporated into $element.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | block-1880588-14.patch | 5.16 KB | tim.plunkett |
| #14 | interdiff.txt | 1.53 KB | tim.plunkett |
| #12 | block-1880588-12.patch | 3.63 KB | tim.plunkett |
| #10 | block-1880588-10.patch | 3.67 KB | tim.plunkett |
| #10 | interdiff.txt | 1.04 KB | tim.plunkett |
Comments
Comment #1
effulgentsia commentedtagging
Comment #2
sunYeah, I've seen this problem in the committed patch already.
We have a similar problem elsewhere in the page rendering process for a long time already: #1473548: CSS classes in $page['#attributes']['class'] are not applied to HTML BODY
Essentially, we need to detach 1) the inner content from 2) the outer/wrapping element.
I guess the solution is as simple as applying this fix wherever the block render array is merged:
Alternatively, we could as well introduce the assumption that the top-level render array level always pertains to the wrapping block element, which in turn would allow callbacks to adjust the #title, #attributes, and so on of the wrapping block template. In turn, every blockRender() callback would be required to always return the actual render elements as sub-elements and never on the top-level; i.e.:
That way, we'd open up the door for block plugins to easily declare or override variables for the wrapping block template; e.g.:
Which in turn would resolve issues like #1302482: Ensure render arrays properly handle #attributes and add them there instead of preprocess hooks
Comment #3
eclipsegc commentedI think I fully support sun's suggestion here. Currently there are a few wtfs around this in that if you were to say, return a form, you have to return array($form) instead of just return $form; and I think sun's suggestion would remove the need for that as well.
Eclipse
Comment #4
sunThinking some more about it, I think we'd ideally do a mixture of both of #2:
Wherever the stuff is invoked/merged/output:
i.e.: Instead of pursuing the disparity further, let's cleanly separate it into:
1) Prepare the block [for rendering]. Allow it to load data and prepare the data.
2) Allow the block plugin to perform adjustments for the wrapping block thingie; e.g., #title, #attributes, #whatever. Data that has been prepared in
prepareBlock()is available in custom/private properties and can be used for conditional/dynamic values.3) Make the block own the render array that it returns; i.e., nothing is merged into what
buildBlockContent()returns. Thus,return $form;works exactly how it is supposed to work. Data that has been prepared inprepareBlock()is available in custom/private properties and can be used to generate the block content.For example:
Comment #5
tim.plunkett#1871696: Convert block instances to configuration entities to resolve architectural issues introduces a render controller and rewrites all of this code. It will be pretty straightforward to write a test and fix with that in place.
Comment #6
xjmComment #7
tim.plunkettModified approach of #4, post BlockRenderController.
Comment #9
tim.plunkettWhoops.
Comment #10
tim.plunkettAh, missed a spot.
Comment #11
sunHmm... This essentially implements #2.
However, in light of our actual goal of #1302482: Ensure render arrays properly handle #attributes and add them there instead of preprocess hooks, I still think it would be better if we'd
1) properly detach the wrapper building from the inner content building
2) inherently allow blocks to load and prepare any data they need (for the wrapper and/or the inner build)
3) call the separate methods to populate the render array accordingly; e.g., like this:
Which is essentially #4, and IMHO would move us really really close to the architecture we're aiming for in #1302482: Ensure render arrays properly handle #attributes and add them there instead of preprocess hooks.
Hat tip: If the user permissions are actually irrelevant for a test, you can skip the entire
drupalCreateUser()procedure and just simply do this instead:That logs in uid 1. Only available in Web Tests.
Comment #12
tim.plunkettThe plugin doesn't care about its wrapper yet. If you want it to, that's definitely a follow-up.
I read #2 and #4, and while both solve our problem, #4 doesn't map to how Block plugins currently function. Seems like a nice to have.
So I went with #2, and it works great.
Thanks for the tip about root_user! That's the only change made here.
Comment #14
tim.plunkettAh, missed openid_block_view_user_login_block_alter().
Comment #15
eclipsegc commentedassuming it passes tests, RTBC
Eclipse
Comment #16
webchickCommitted and pushed to 8.x. Thanks!