Support from Acquia helps fund testing for Drupal Acquia logo

Comments

foopang’s picture

Status: Active » Needs review
FileSize
5 KB
foopang’s picture

Status: Needs review » Needs work

The last submitted patch, convert-html.tpl_.php-twig-1961872-1.patch, failed testing.

nikkubhai’s picture

Status: Needs work » Needs review
FileSize
5 KB

Status: Needs review » Needs work

The last submitted patch, convert-html.tpl_.php-twig-1961872-1_0.patch, failed testing.

star-szr’s picture

@nikkubhai - Welcome to Twigland! An interdiff is nice when making changes to patches :) I think this hunk from #2 is correct though, there should be no space before {{ html_attributes }}:

+++ b/core/modules/system/templates/html.html.twigundefined
@@ -0,0 +1,71 @@
+<html{{ html_attributes }}>

Running the failing tests locally should help track down where the failures and exceptions are coming from.

star-szr’s picture

Information on enabling simpletest module and running tests locally:
http://drupal.org/node/519364
http://drupal.org/node/30036

nikkubhai’s picture

The exception message:
page_top could not be found in _context in "core/modules/system/templates/html.html.twig" at line 67

can be removed by using

{% if page_top %}
  {{ page_top }} 
{% endif %}
star-szr’s picture

Issue tags: +Needs manual testing

Tagging.

star-szr’s picture

Assigned: Unassigned » star-szr

I'm looking into this one, definitely some work needed in the preprocess/process layers.

star-szr’s picture

Status: Needs work » Needs review
FileSize
4.37 KB
6.74 KB

Updated docs throughout and t filter per http://drupal.org/node/1823416#filters.

The template_process_html() tweak should fix most of the test failures. Drupal\system\Tests\Bootstrap\PageCacheTest is still failing locally for unknown reasons, let's see if anything else is broken.

star-szr’s picture

Assigned: star-szr » Unassigned

Turns out Drupal\system\Tests\Bootstrap\PageCacheTest fails locally on HEAD for me.

thedavidmeister’s picture

#12 - I get that too! but for every issue I work on and it's been happening for months.

thedavidmeister’s picture

Status: Needs review » Needs work

#11: I have some questions..

why do we need to drupal_render the page top/bottom in a process function?

why do we need a process function?

also, please remove any references to PHP data types from Twig template docs.

star-szr’s picture

Removing the drupal_render() from page top/page bottom results in half of the CSS and JavaScript files not being included, so I think it's fine to keep them. Should have noted that here though. We avoid drupal_render() so that we pass render arrays rather than strings to templates (and avoid unnecessary rendering), but in this case I think any alterations to page_top and page_bottom need to happen in the preprocess/process layers.

I haven't experimented yet but I think moving the logic in template_process_html() to the end of template_preprocess_html() at this point would break things. I'm thinking RDF for example, I'll give it a shot though.

Edited to expand on first paragraph.

star-szr’s picture

Status: Needs work » Needs review
FileSize
2.21 KB
6.71 KB

Moving the logic from template_process_html() to the end of template_preprocess_html() didn't obviously break anything, but in my opinion doing so at this time would limit the usefulness of MODULE_preprocess_html(), THEME_preprocess_html(), and related hooks. At this stage I think we should keep template_process_html() and consider removing it as part of a greater shift - #1843650: Remove the process layer (hook_process and hook_process_HOOK).

Updated docs in html.html.twig per #14 and http://drupal.org/node/1823416#datatypes, and added @see template_process_html().

thedavidmeister’s picture

Issue tags: -Needs manual testing

#16 - I'm happy with those revisions to the docs and your explanation of the process stuff.

Is this really a manual testing issue?

If this template didn't work at all you'd be looking at about 50k failed tests. If there's some part of the template you're worried about, like a valid DOCTYPE or attributes being applied to the html and body tags correctly, and we don't already have automated tests for those then we should be writing them right now as they're very important to get right.

thedavidmeister’s picture

Assigned: Unassigned » thedavidmeister

looking into tests.

thedavidmeister’s picture

Assigned: thedavidmeister » Unassigned
Status: Needs review » Needs work

There's an error being thrown on my local:

"User warning: page_top could not be found in _context in "core/modules/system/templates/html.html.twig" at line 49 in Drupal\Core\Template\TwigTemplate->getContextReference() (line 50 of core/lib/Drupal/Core/Template/TwigTemplate.php)."

It only seems to appear when navigating the admin sections using the Overlay - I think overlay_page_alter() or a related function is causing trouble. The error appears in either the overlay or in the parent page behind the overlay. Seeing the error and refreshing the page can cause it to disappear if the overlay is not active. If the overlay is active and the error has not appeared then refreshing the page causes it to appear in the parent page.

Adding this to the template resolves the issue for me but I don't know enough about the problem to know whether this is the best solution:

    {% if page_top %}
      {{ page_top }}
    {% endif %}
    {{ page }}
    {% if page_bottom %}
      {{ page_bottom }}
    {% endif %}
star-szr’s picture

Assigned: Unassigned » star-szr

Great find @thedavidmeister, I'm on it.

thedavidmeister’s picture

Issue tags: +Needs manual testing

I guess I also answered my own question.

widukind’s picture

Assigned: star-szr » widukind

reassigning this to myself, OKed with @cottser.

star-szr’s picture

+++ b/core/modules/system/templates/html.html.twigundefined
@@ -0,0 +1,53 @@
+ * @see template_process()

We can remove this @see, template_process() itself is gone in D8 - #1290694: Provide consistency for attributes and classes arrays provided by template_preprocess().

widukind’s picture

Status: Needs work » Needs review
FileSize
6.72 KB
796 bytes

As @thedavidmeister was suspecting, the overlay module is causing the error.

overlay_page_alter() is setting the "#access" flag to FALSE in the "page_top" renderable array, since it identifies it as a region to be skipped.

/**
 * Implements hook_page_alter().
 */
function overlay_page_alter(&$page) {
  // If we are limiting rendering to a subset of page regions, deny access to
  // all other regions so that they will not be processed.
  if ($regions_to_render = overlay_get_regions_to_render()) {
    $skipped_regions = array_diff(element_children($page), $regions_to_render);
    foreach ($skipped_regions as $skipped_region) {
      $page[$skipped_region]['#access'] = FALSE;
    }
  }
...

this is causing drupal_render() to return NULL further downstream in template_process_html() when it is trying to render "page_top".

Not sure what to do about this, other than checking for a truthy value of "page_top" before outputting it in the template.
("page_bottom" does not seem to be affected by that, so I left it as-is)

Status: Needs review » Needs work
Issue tags: -Needs manual testing, -Twig

The last submitted patch, 1961872-24.patch, failed testing.

c4rl’s picture

Status: Needs work » Needs review

#24: 1961872-24.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs manual testing, +Twig

The last submitted patch, 1961872-24.patch, failed testing.

Anonymous’s picture

Issue summary: View changes

Update remaining

star-szr’s picture

Status: Needs work » Needs review
FileSize
471 bytes
6.72 KB

I double checked the patch to see if it was just testbot being cranky and it wasn't. This just fixes the syntax on the if for now.

thedavidmeister’s picture

#24: 1961872-24.patch queued for re-testing.

thedavidmeister’s picture

Status: Needs review » Needs work

Wrapping the page_top in an if inside the Twig template is a hack, especially if it's undocumented and the page_bottom isn't also wrapped in an if - Apologies for suggesting it in the first place.

FWIW, I tried to replicate the same bug for page_bottom and could only do it when I removed $variables['page_bottom'] .= drupal_get_js('footer'); from the process function - showing that this really is just an issue with data types, and a clue for a fix :)

What about casting the variables to strings in template_process_html() instead, like this:

// Render page_top and page_bottom into top level variables.
$variables['page_top'] = isset($variables['page']['page_top']) ? (string) drupal_render($variables['page']['page_top']) : '';
$variables['page_bottom'] = isset($variables['page']['page_bottom']) ? (string) drupal_render($variables['page']['page_bottom']) : '';

Or even this - #1975442: drupal_render() should always return a string..

widukind’s picture

Status: Needs work » Needs review
FileSize
6.7 KB
1.68 KB

As outlined in comment #30, I removed the conditional from the template.

For the sake of moving along, I added type casting to template_process_html().

Modifying drupal_render() to always return a string is clearly the way to go. If and when this passes then the type casting becomes obsolete and should be removed.

thedavidmeister’s picture

thedavidmeister’s picture

Status: Needs review » Needs work

#1975442: drupal_render() should always return a string. just got committed. We should be able to remove the type casting now.

widukind’s picture

Status: Needs work » Needs review
FileSize
1.24 KB
6.68 KB

removed type casting.

thedavidmeister’s picture

Status: Needs review » Needs work
Issue tags: +Novice

+ * variable, already prepared to be output as TITLE tag. Ths variable may

Ths?

+ * - slogan: The slogan of the site, if any, and if there is no title.

This sentence is wildly awkward.

 * - page: The rendered page content.
+ * - page_bottom: Final closing markup from any modules that have altered the
+ *   page. This variable should always be output last, after all other dynamic
+ *   content.
+ * - page_top: Initial markup from any modules that have altered the page. This
+ *   variable should always be output first, before all other dynamic content.

I feel like these variables could be better documented in the order they are required to be rendered - page_top, page, page_bottom.

c4rl’s picture

Made documentation changes as suggested in #35.

Interdiff with respect to #34.

c4rl’s picture

Status: Needs work » Needs review
c4rl’s picture

Assigned: widukind » Unassigned
shanethehat’s picture

I can only see two little nitpicks:

  * @see system_elements()
- * @see html.tpl.php
+ * @see html.html.twig

There's no need to @see the twig file that this function belongs to. That's what the 'Default template' statement is for.

  * @see template_preprocess_html()
- * @see html.tpl.php
+ * @see html.html.twig

It's enough to just refer to the preprocess, not the template.

star-szr’s picture

Status: Needs review » Needs work

Agreed with #39, good catches.

+++ b/core/modules/system/templates/html.html.twigundefined
@@ -8,21 +8,18 @@
+ * - page_top: Initial rendered markup. This should be printed before page.
+ * - page: The rendered page markup.
+ * - page_bottom: Closing rendered markup. This variable should be printed after
+ *   page.

When referring to the page variable in page_top and page_bottom, let's put 'page' in single quotes per http://drupal.org/node/1823416#variables-inline.

shanethehat’s picture

Status: Needs work » Needs review
FileSize
6.34 KB
899 bytes

Fixed the two minor points from #39

shanethehat’s picture

And from #40

thedavidmeister’s picture

Status: Needs review » Reviewed & tested by the community

RTBC then?

shanethehat’s picture

+1

shanethehat’s picture

Issue summary: View changes

We'll cleanup scattered docs later.

jenlampton’s picture

Issue summary: View changes

remove sand

alexpott’s picture

Issue tags: +needs profiling

The conversion looks good... we just need to some profiling done.

star-szr’s picture

Issue tags: -Novice, -Needs manual testing, -needs profiling
FileSize
528 bytes
6.31 KB

Small performance tweak attached, but even without it I think the performance is definitely acceptable.

Profiling done on a node page using the Stark theme and APC class loader enabled.

The first is HEAD vs. itself - to show that the baseline run used for profiling is accurate.

The second is HEAD vs. #42.

The third is HEAD vs. the attached patch.

=== html-head..html-head compared (518e77f228c59..518e79892b1de):

ct : 29,106|29,106|0|0.0%
wt : 298,247|298,197|-50|-0.0%
cpu : 275,468|275,421|-47|-0.0%
mu : 27,190,952|27,190,952|0|0.0%
pmu : 27,246,256|27,246,256|0|0.0%

http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=518e77f228c59&...

=== html-head..html-1961872-42 compared (518e77f228c59..518e79fd1bf6e):

ct : 29,106|29,201|95|0.3%
wt : 298,247|299,203|956|0.3%
cpu : 275,468|276,890|1,422|0.5%
mu : 27,190,952|27,230,136|39,184|0.1%
pmu : 27,246,256|27,280,208|33,952|0.1%

http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=518e77f228c59&...

=== html-head..html-1961872-46 compared (518e77f228c59..518e79c023047):

ct : 29,106|29,193|87|0.3%
wt : 298,247|298,789|542|0.2%
cpu : 275,468|274,673|-795|-0.3%
mu : 27,190,952|27,226,680|35,728|0.1%
pmu : 27,246,256|27,276,592|30,336|0.1%

http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=518e77f228c59&...

alexpott’s picture

Title: Convert html.tpl.php to Twig » [Ready] Convert html.tpl.php to Twig
Status: Reviewed & tested by the community » Closed (duplicate)
alexpott’s picture

Title: [Ready] Convert html.tpl.php to Twig » [READY] Convert html.tpl.php to Twig

Fixing title...

star-szr’s picture

Status: Closed (duplicate) » Needs review
FileSize
6.26 KB
star-szr’s picture

Status: Needs review » Closed (duplicate)
star-szr’s picture

Issue summary: View changes

Updated issue summary.

alexpott’s picture

Title: [READY] Convert html.tpl.php to Twig » Convert html.tpl.php to Twig
Status: Closed (duplicate) » Fixed

Committed 8ec70c2 and pushed to 8.x. Thanks!

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

Anonymous’s picture

Issue summary: View changes

Updated issue summary.