Problem/Motivation
Theme development for drupal is too complicated, with too many layers. We aim to remove the whole Process layer, but that can only be done in small pieces.
Proposed resolution
In order to remove the process layer, we will need to make sure that all variables added to templates are added on the preprocess layer. Currently some variables such as page title and breadcrumbs are aded at the process layer, and they will need to be moved.
Remaining tasks
- add breadcrumbs in preprocess layer
- add page title in preprocess layer
- flatten arrays to stings as part of the rendering layer.
API changes
TBD
Blockers (issues)
#1843668: Move building of breadcrumb render array from template_process_page() to template_preprocess_page()
#1843678: Move building of messages render array from template_process_page() to template_preprocess_page()
Related issues
#1843650: Remove the process layer (hook_process and hook_process_HOOK)
Comment | File | Size | Author |
---|---|---|---|
#29 | drupal-move-title-from-process-1589968-29.patch | 4.32 KB | markhalliwell |
#25 | move-vars-to-preprocess-1589968-25.patch | 1006 bytes | DarthDrupal |
#15 | 1589968-8.patch | 1.07 KB | Pancho |
#8 | 1589968-8-do-not-test.patch | 1.07 KB | star-szr |
#8 | 1589968-8-combined.patch | 7.98 KB | star-szr |
Comments
Comment #1
cr0ss CreditAttribution: cr0ss commentedAttached patch is moving title, breadcrumb, messages to preprocess layer from template_process_page.
Comment #2
sunI'm not familiar with what has been discussed regarding template variable processing for Twig templates, but since Twig is only one possible template engine, I don't think that this is the right approach.
The reason for why we have the separate process step is to properly account for race conditions.
I.e., you are no longer able to adjust/inject/alter the breadcrumb, if it is rendered/processed too early. You are no longer able to change the page title through regular functions, if it is rendered too early. You are no longer able to output any status/info/warning/error messages, if they are rendered too early (they will appear on the next page request instead).
Also, this potentially has a negative impact on performance.
This is directly related to the breadcrumb processing, since the page title is derived from the active trail (~breadcrumb) by default, unless a manual page title has been set via drupal_set_title() in the page building process.
The inline comment already clarifies why this is done as the very very last step of template variable processing:
If you move this earlier, debug(), dsm(), dpm(), drupal_set_message(), and many other functions cease to work when being called from template preprocess functions.
Comment #2.0
jenlamptonadd another todo
Comment #2.1
jenlamptonadded meta issue
Comment #3
jenlamptonBreadcrumbs: It sounds like the problem with breadcrumbs is that they are rendered / processed before they make it to the template. Let's make breadcrumbs into a renderable so that we can work with it like everything else, and only render/flatten/print it using a __toString method once we get to the template file.
See #1843668: Move building of breadcrumb render array from template_process_page() to template_preprocess_page()
Messages I think the same solution might exist for messages, If they were renderable we would be able to adjust them as necessary, and they would only get flattened as they are being injected into the template.
See #1843678: Move building of messages render array from template_process_page() to template_preprocess_page()
Page titles I agree page titles present a tricky problem, but I'm not sure that simply moving them to the process layer was the best solution. We want to remove the process layer entirely from Drupal 8, so that leaves us two options: move addition to the page title up to preprocess (where theme devs can get their hands on it), or push it back to render time - a solution I like for renderables (like breadcrumbs and messages) but I'm not so sure about doing that for the Page Title. I'm open to other ideas here :)
Let's narrow this issue to focus specifically on removing the addition of new variables from template_process_page. (Updating title). I've opened #1843650: Remove the process layer (hook_process and hook_process_HOOK) as the meta issue for removal of the entire process layer, we can track all the different pieces of this there.
Comment #4
bdragon CreditAttribution: bdragon commentedAgreed. The stuff in template_process_page is there only because it is a set of things that are affected by the rendering of the rest of the page. Adding css files during preprocess, catching as many messages as possible, messing with the page title during preprocess, messing with breadcrumb during preprocess.
For page-level it seems like it's still necessary to have some special cases for these things, or maybe do a second pass for these...
Comment #5
jenlamptonI agree that page is special, and I think it's okay to have a special case for the page template where things get added in later than in all other templates. But the process layer needs to go - and from everywhere. Maybe the Title can get handled with something similar to RenderWrapper, that happens only once per page.
Comment #6
jenlamptonSince we already have sub issues for breadcrumb and messages, retitling this one to be more specific.
Comment #7
jenlamptonuhm, yeah
Comment #8
star-szrAgreed with the RenderWrapper idea - here is a patch that combines #2004286-60: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class with using the RenderWrapper for drupal_get_title(). Second patch is without the code from the other issue.
Comment #9
jenlamptonNice! page titles working for me from the process layer.
Does this patch (1589968-8-do-not-test.patch) depend on #2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class?
Probably also:
#1843678: Move building of messages render array from template_process_page() to template_preprocess_page()
#1843668: Move building of breadcrumb render array from template_process_page() to template_preprocess_page()
Comment #10
star-szrYes, the -do-not-test patch depends on #2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class. I think we could remove template_process_page() on the (to be revised) patch on the meta.
Edit: Although I guess that would leave us with an empty template_process_page()…
Comment #11
alexpottNeeds a test for the new RenderWrapper
Comment #12
star-szrOk, tests added for RenderWrapper earlier today: #2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class. 1589968-8-do-not-test.patch depends on that issue and still applies fine.
So back to RTBC per #9 but #2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class would need to be committed first.
Comment #13
YesCT CreditAttribution: YesCT commentedThis issue was RTBC and passing tests on July 1, the beginning of API freeze.
Comment #14
alexpott#2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class has been committed so lets get a patch based on the do not test patch in #8 tested...
Comment #15
Pancho1589968-8-do-not-test.patch in #8 still applied.
Just a rename, so it gets tested.
Comment #16
ericrdb CreditAttribution: ericrdb commentedApplied the patch to
HEAD is now at b416a37 Issue #1941286 by scor, Eric_A: Remove the process layer (rdf module).
Title, Slogan and breadcrumbs are working. Cheers
Comment #17
Fabianx CreditAttribution: Fabianx commentedAnd back to RTBC
Comment #18
alexpott#2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class has been reverted...
Comment #19
jenlampton#2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class is back to RTBC
back to RTBC too :)
Comment #20
alexpottHo hum... no it's not... I'm just going to postpone this on #2004286: Defer calls to drupal_get_* functions until printed inside a template by adding a RenderWrapper class Cottser's work on adding tests to that issue is important.
Comment #21
jenlamptonun postponed! :) (patch still applies, I just checked)
Comment #22
alexpott#15: 1589968-8.patch queued for re-testing.
Comment #24
star-szrNeeds a quick reroll.
Comment #25
DarthDrupal CreditAttribution: DarthDrupal commentedrerolled
Comment #26
DarthDrupal CreditAttribution: DarthDrupal commentedremoved needs reroll tag
Comment #27
star-szrTitle is all that's left in template_process_page() now that #1843668: Move building of breadcrumb render array from template_process_page() to template_preprocess_page() has been committed, so this patch should actually remove the whole template_process_page() function now.
Comment #28
star-szrAnd technically it needs a reroll as well :)
Comment #29
markhalliwellRerolled. Did a quick S&R for template_process_page and removed/changed references to it in any remaining docs.
Comment #30
markhalliwell.
Comment #31
Fabianx CreditAttribution: Fabianx commentedThis is RTBC - provided testbot is green!
Comment #32
markhalliwellTest passed
Comment #33
alexpottCommitted 5d649f8 and pushed to 8.x. Thanks!
Comment #34.0
(not verified) CreditAttribution: commentedblockers