Problem/Motivation
Layout discovery doesn't load layout suggestions unless the layout definition is prefixed with layout__ and the template with layout--.
This break any existing site using the (deprecated) Layouts contrib module, where the prefixing wasn't necessary.
Additionally site-builders and developers get confused as twig debug comments suggest wrong [as in: not-prefixed] template suggestions names, i.e. (from: #2905197: Template override is not working):
layouts definitions file: naurodvolleys.layouts.yml
naurodvolleys_1x1:
label: "naurodvolleys 1x1"
category: "naurodvolleys"
template: "templates/content-layout/naurodvolleys_1x1"
regions:
main:
label: "Main"
Template suggestions:

Target suggestion: naurodvolleys-1x1--node-result-1x1.html.twig

Suggestion is not loaded.
For further investigation you can read #2862683: 'base hook' key prevents template suggestions from working comments from #25 on going.
Proposed resolution
The first task should be to understand if prefixing layouts with layout__/layout-- as core does is the right way.
- If it is then we need to update the documentation pages How to register layouts and How to upgrade from Layout Plugin, together with updating the twig debug comment suggestions.
- if it is NOT, then we need to fix the issue in order for layout suggestions to be loaded correctly.
@tim.plunkett on #9 confirmed this is actually a bug, themes and modules layout templates suggestions needs to be loaded in accordance with their definitions.
Remaining tasks
Define what is the right way to name layout bundles and their templates, if the layout__/layout-- prefixes are mandatory. (#9Update the issue summary with the right proposed resolution when task 1) is complete#11- Code a solution
- Update the documentation if necessary
User interface changes
This is a pure code change, so no UI changes expected.
API changes
There may be Layout API changes, depending what the result of task 1) will be.
| Comment | File | Size | Author |
|---|---|---|---|
| #41 | interdiff_39-41.txt | 729 bytes | ravi.shankar |
| #41 | 2911996-41.patch | 7.89 KB | ravi.shankar |
| #39 | drupal-layout_discovery-2911996-39-d95.patch | 7.78 KB | vladimiraus |
| #11 | 2911996-layout-11.patch | 5.14 KB | gambry |
| #9 | 2911996-layout-9.patch | 6.65 KB | tim.plunkett |
Comments
Comment #2
gambryLinking related issue #2905197: Template override is not working and #2862683: 'base hook' key prevents template suggestions from working
Comment #3
gambryUpdating IS with mentioning the investigation bit done from #2862683: 'base hook' key prevents template suggestions from working #25 and following comments.
Comment #4
gambryComment #5
tim.plunkettLet's prove that it works first.
Comment #7
tim.plunketttemplate_preprocess_layout() is no longer firing for these layouts, as suspected.
Comment #8
gambry@tim.plunkett so this is actually a real bug, as layout are not supposed to have the prefixes layout__/layout-- ?
If so I will update the IS and start looking at a fix.
Comment #9
tim.plunkettIt is not documented anywhere that layout templates are required to have the
layout--prefix, and IMO this is a bug deep in the theme system.Consider these two tests. They are completely identical tests, but one is a Kernel test and one is a Functional test. The Kernel test passes, the Functional test fails.
Somewhere in between these two lies the bug.
Comment #11
gambryUpdating the issue summary as we now know this is a bug.
@tim.plunkett and I have discussed the result of test failing on #9. It looks like when layout templates overrides exist (for example in the stable theme on that test) then
template_preprocess_layoutdoesn't exist in the "preprocess functions" array. This may or may not be related to this bug.Attaching a test to prove this.
I'll have a look and open another issue if the two bugs are not related.
Setting Needs Review just to trigger testbot. This issue still needs work.
Comment #14
tim.plunkettComment #15
vladimirausNot a complete solution but will allow override templates.
IDs were renamed from `layout_x` to `layout__x`.
Previous layouts with originals IDs are still there but labelled deprecated.
Probably needs hook_update to check if we are using old layouts.
Comment #16
vladimirausComment #18
borisson_The latest patch (#15) doesn't include the tests added in #11 anymore. It should, let's add those back in.
Comment #19
tim.plunkettAlso note that #2938132: Ship layouts that make sense with Layout Builder's concept of sections landed and we have more layouts.
Comment #20
vladimirausThis patch include:
* deprecation of all templates with `layout_x` IDs in
layout_builderandlayout_buildermodules.* introduction of replacement templates with `layout__x` IDs.
* tests from #11
Comment #22
vladimirausRemoving accidental commits.
This patch includes:
* deprecation of all templates with `layout_x` IDs in
layout_builderandlayout_buildermodules.* introduction of replacement templates with `layout__x` IDs.
* tests from #11
Comment #23
vladimirausComment #25
vladimirausFixing tests.
This patch includes:
* deprecation of all templates with `layout_x` IDs in
layout_builderandlayout_buildermodules.* introduction of replacement templates with `layout__x` IDs.
* tests from #11
Comment #31
adam3145 commentedWhere is this at as I am still having this issue.
Comment #35
golddragon007 commentedWell, this is not the only issue, I have two template files with the same name in two different directories and it picks the wrong one...
i,e:
*.layouts.yml:
banner:
label: Banner
category: Custom
template: templates/layouts/banner
[...]
And I have two files, one templates/layouts/banner.html.twig and one templates/components/banner.html.twig, and it picks the templates/components/banner.html.twig instead the one that is explicitly specified... (within the same theme)
Comment #36
vladimirausComment #37
vladimirausMaking sure it works for latest branch.
Comment #39
vladimirausFixing tests.
Comment #41
ravi.shankar commentedFixing failed test of patch #39.
Comment #43
tim.plunkettIn #9 I found a bug elsewhere in the system. I don't think doubling the number of layout plugins is a reasonable compromise...
Can we get back to trying to fix the underlying bug instead of treating the symptom?
Comment #46
anybodyMight this be caused by #2752443: Incorrect order and duplicate theme hook suggestions?