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)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cr0ss’s picture

Attached patch is moving title, breadcrumb, messages to preprocess layer from template_process_page.

sun’s picture

I'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).

+++ b/core/includes/theme.inc
@@ -2634,22 +2637,7 @@ function template_preprocess_page(&$variables) {
-  if (!isset($variables['breadcrumb'])) {
-    // Build the breadcrumb last, so as to increase the chance of being able to
-    // re-use the cache of an already rendered menu containing the active link
-    // for the current page.
-    // @see menu_tree_page_data()
-    $variables['breadcrumb'] = theme('breadcrumb', array('breadcrumb' => drupal_get_breadcrumb()));
-  }

Also, this potentially has a negative impact on performance.

+++ b/core/includes/theme.inc
@@ -2634,22 +2637,7 @@ function template_preprocess_page(&$variables) {
-  if (!isset($variables['title'])) {
-    $variables['title'] = drupal_get_title();
-  }

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.

+++ b/core/includes/theme.inc
@@ -2634,22 +2637,7 @@ function template_preprocess_page(&$variables) {
-  // Generate messages last in order to capture as many as possible for the
-  // current page.
-  if (!isset($variables['messages'])) {
-    $variables['messages'] = $variables['show_messages'] ? theme('status_messages') : '';
-  }

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.

jenlampton’s picture

Issue summary: View changes

add another todo

jenlampton’s picture

Issue summary: View changes

added meta issue

jenlampton’s picture

Priority: Major » Normal

Breadcrumbs: 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.

bdragon’s picture

Title: Move the addition of all new variables from the process to the preprocess layer » Remove template_process_page() / move variables added here to a different place.
Priority: Normal » Major

Agreed. 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...

jenlampton’s picture

I 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.

jenlampton’s picture

Title: Remove template_process_page() / move variables added here to a different place. » Move Title from preprocess to process, remove template_process_page()
Priority: Normal » Major

Since we already have sub issues for breadcrumb and messages, retitling this one to be more specific.

jenlampton’s picture

Title: Move Title from preprocess to process, remove template_process_page() » Move Title from process to preprocess, remove template_process_page()

uhm, yeah

star-szr’s picture

Status: Active » Needs review
Issue tags: +theme system cleanup
FileSize
7.98 KB
1.07 KB

Agreed 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.

jenlampton’s picture

star-szr’s picture

Yes, 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()…

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs work

Needs a test for the new RenderWrapper

star-szr’s picture

Status: Needs work » Reviewed & tested by the community
YesCT’s picture

Issue tags: +RTBC July 1

This issue was RTBC and passing tests on July 1, the beginning of API freeze.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs work

#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...

Pancho’s picture

Status: Needs work » Needs review
FileSize
1.07 KB

1589968-8-do-not-test.patch in #8 still applied.
Just a rename, so it gets tested.

ericrdb’s picture

Status: Needs review » Reviewed & tested by the community

Applied 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

Fabianx’s picture

And back to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
jenlampton’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Postponed

Ho 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.

jenlampton’s picture

Status: Postponed » Reviewed & tested by the community

un postponed! :) (patch still applies, I just checked)

alexpott’s picture

#15: 1589968-8.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work
Issue tags: +theme system cleanup, +RTBC July 1

The last submitted patch, 1589968-8.patch, failed testing.

star-szr’s picture

Issue tags: +Novice, +Needs reroll

Needs a quick reroll.

DarthDrupal’s picture

Status: Needs work » Needs review
FileSize
1006 bytes

rerolled

DarthDrupal’s picture

Issue tags: -Needs reroll

removed needs reroll tag

star-szr’s picture

Status: Needs review » Needs work

Title 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.

star-szr’s picture

Issue tags: +Needs reroll

And technically it needs a reroll as well :)

markhalliwell’s picture

Status: Needs work » Needs review
FileSize
4.32 KB

Rerolled. Did a quick S&R for template_process_page and removed/changed references to it in any remaining docs.

markhalliwell’s picture

Issue tags: -Needs reroll

.

Fabianx’s picture

This is RTBC - provided testbot is green!

markhalliwell’s picture

Status: Needs review » Reviewed & tested by the community

Test passed

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 5d649f8 and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

blockers