Problem/Motivation
Similar to templates like views-view-list.html.twig that support attributes for each row, layouts need attributes for each region.
This will allow dynamically specifying attributes, which is necessary for things like drag-n-drop UIs.
Proposed resolution
Add a region_attributes
variable to layout templates
Currently, the manual adding of classes like 'layout__region' and 'layout__region--second' is kept in the template, but could now be handled dynamically if so desired.
Noteworthy: Display Suite and Bootstrap Layouts both have implemented their own per-region attribute system, which won't conflict with this change, and theirs could easily move to this approach.
Remaining tasks
N/A
User interface changes
N/A
API changes
Layout templates should make the following change:
- <div class="layout__region layout__region--content">
+ <div {{ region_attributes.content.addClass('layout__region', 'layout__region--content') }}>
This is not a true API change since the code is experimental.
Comments
Comment #2
tim.plunkettComment #4
tim.plunkettThe fixes are fine but the test is blocked by #2862683: 'base hook' key prevents template suggestions from working
Might try to come up with another approach for the test to stay unblocked
Comment #5
tim.plunkettWorking around #2886187: Document the regex in Registry::postProcessExtension() used to find preprocess functions for now.
Comment #6
tim.plunkettThis is the key part, preprocess adding classes to region markup.
Comment #7
tim.plunkettUpdated the IS to mention that this is similar to DS and Bootstrap Layouts.
Comment #8
EclipseGc CreditAttribution: EclipseGc commentedfirst-above
second-above
Can we do this just as:
{{ attributes.addClass('layout-example-1col', 'clearfix') }}
instead?
Tad bit of tweaking and this will look RTBC to me.
Eclipse
Comment #9
tim.plunkett1+2) nice catch! Went back over it with diff color-words and found some other mistakes
3) Yes, agreed. I'm keeping that approach in the real templates since it's what the rest of core does. But I minimized the changes to the test layouts.
Additionally, made the same changes to threecol 25/50/25 and the generic layout.html.twig
Comment #10
tim.plunkettComment #11
Manuel Garcia CreditAttribution: Manuel Garcia as a volunteer and at Appnovation commented#8 has been addressed, all layouts templates covered, this looks great to me, rtbcing
Comment #12
EclipseGc CreditAttribution: EclipseGc commentedRTBC++
Comment #13
tim.plunkett@effulgentsia points out that we don't even need the @todo pointing to #2886187: Document the regex in Registry::postProcessExtension() used to find preprocess functions, or that issue at all, because the simpler
template_preprocess_layout_test_2col
already works.Comment #14
EclipseGc CreditAttribution: EclipseGc commentedRTBC pending testbot
Eclipse
Comment #15
larowlanCan we have a change record for this.
I realize that layout discovery is experimental, but the fact is anyone using DS on 8.3 is most likely to be using it.
And they are most likely to have their own layouts, so will need to make similar updates.
Comment #16
tim.plunkettAdded https://www.drupal.org/node/2886860
Comment #17
WidgetsBurritos CreditAttribution: WidgetsBurritos at Rackspace commented+1 Change record looks good to me.
Comment #18
tacituseu CreditAttribution: tacituseu commentedchange record: s/row_attributes/region_attributes ?
Comment #19
tim.plunkettChanged.
Anyone can edit CRs, could have just fixed it :)
Comment #20
larowlanUpdating issue credit and title
Comment #21
larowlanComment #22
larowlanI reviewed this patch and applied it locally.
I checked both of the .layouts.yml in core (one in layout_discovery.module and one in layout_test.module) and made sure that each of the defined layout templates were updated to use the new attributes - all were.
Committed as 7996c0f and pushed to 8.4.x.
Published the change record.
Thanks for your work.
Comment #24
kim.pepperCongrats on your first core commit, larowlan!