Issue #2151105 by joelpittet, longwave, c4rl, IshaDakota, pplantinga, gnuget, jeanfei, sbudker1: Convert theme_system_admin_index() to Twig

Task

Convert theme_system_admin_index() to a Twig template.

Remaining tasks

  • Patch
  • Patch review
  • Manual testing
  • Profiling

Steps to test

Navigate to /admin/index

Files: 
CommentFileSizeAuthor
#45 2151105-twig-system_admin_index-45-reroll.patch4.15 KBjoelpittet
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 69,979 pass(es). View
#42 interdiff.txt1.3 KBjoelpittet
#42 2151105-twig-system_admin_index-42.patch4.15 KBjoelpittet
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 69,875 pass(es), 2 fail(s), and 0 exception(s). View
#37 interdiff.txt695 bytesjoelpittet
#36 2151105-twig-system_admin_index-36.patch4.1 KBjoelpittet
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,411 pass(es). View
#34 2151105-twig-system_admin_index-34.patch4.12 KBjoelpittet
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,427 pass(es). View
#31 2151105-29-rerolled.patch4 KBjoelpittet
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,297 pass(es). View
#29 2151105-29.patch4.02 KBCottser
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,366 pass(es). View
#21 interdiff-2151105.txt1.84 KBlongwave
#21 2151105-twig-system_admin_index-21.patch4.02 KBlongwave
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,117 pass(es), 1 fail(s), and 1 exception(s). View

Comments

joelpittet’s picture

Status: Active » Needs review
FileSize
4.04 KB
PASSED: [[SimpleTest]]: [MySQL] 59,308 pass(es). View

Split from system module twig conversion meta.

Cottser’s picture

Issue summary: View changes

Adding a commit message to the issue summary so the folks who already worked on #1987410: [meta] system.module - Convert theme_ functions to Twig and #1898454: system.module - Convert PHPTemplate templates to Twig (comment #41 and above aka @c4rl) get credit.

Cottser’s picture

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

Tagging for reroll.

longwave’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
4.04 KB
FAILED: [[SimpleTest]]: [MySQL] 59,835 pass(es), 48 fail(s), and 40 exception(s). View

Patch applied with fuzz only, rerolled.

Status: Needs review » Needs work

The last submitted patch, 4: 2151105-twig-system_admin_index-4.patch, failed testing.

longwave’s picture

Status: Needs work » Postponed
joelpittet’s picture

Status: Postponed » Needs review
FileSize
4.04 KB
PASSED: [[SimpleTest]]: [MySQL] 59,933 pass(es). View

Why postponing this? It uses that theme but doesn't have any conflicts between them I'm pretty sure?

longwave’s picture

All the fails in #4 were related to system_compact_link, and I thought that was why - maybe not?

Cottser’s picture

Yeah I think this just got fuzzed wrong maybe?

longwave’s picture

Seems like somehow it got applied to the wrong part of hook_theme(), and I didn't spot that earlier. Sorry!

joelpittet’s picture

No worries, at least you found what it was. That is strange it would do that, I wonder if one of the hunks is so similar that when head moved they magically lined up?

Cottser’s picture

Issue tags: +Twig conversion
Cottser’s picture

Cottser’s picture

Issue summary: View changes

Updating testing steps in issue summary.

joelpittet’s picture

Issue tags: -Needs profiling

Profile of all 3 patches and confirmed they were all on the page.
#2151107-1: Convert theme_system_compact_link() to Twig
#2151105-7: Convert theme_system_admin_index() to Twig
#2151089-11: Convert theme_admin_block() to Twig

Scenario

  • /admin/index as front page.
  • Full permissions to all users.
=== 8.x..8.x compared (53195a48b6f09..53195b6957e56):

ct  : 141,571|141,571|0|0.0%
wt  : 699,947|697,654|-2,293|-0.3%
cpu : 694,237|691,839|-2,398|-0.3%
mu  : 32,653,568|32,653,568|0|0.0%
pmu : 32,751,144|32,751,144|0|0.0%

http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=53195a48b6f09&...

=== 8.x..2151089-theme_system compared (53195a48b6f09..53195bb0cc668):

ct  : 141,571|143,024|1,453|1.0%
wt  : 699,947|703,391|3,444|0.5%
cpu : 694,237|697,723|3,486|0.5%
mu  : 32,653,568|33,003,928|350,360|1.1%
pmu : 32,751,144|33,095,584|344,440|1.1%

http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=53195a48b6f09&...

joelpittet’s picture

Here's the manual testing for this. The raw output from /admin/index is in the text files.

Beginning and end

Divs around the admin_blocks

Cottser’s picture

+++ b/core/modules/system/system.admin.inc
@@ -215,55 +217,35 @@ function theme_admin_page($variables) {
+          'show' => TRUE,

We'll probably want to remove this line pending #2151089: Convert theme_admin_block() to Twig.

longwave’s picture

That is already removed in #2151089: Convert theme_admin_block() to Twig, this will conflict if that patch is committed first.

Cottser’s picture

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

@longwave - right, good to know! Since the one here was refactored a bit I didn't catch that the first time around.

  1. +++ b/core/modules/system/system.admin.inc
    @@ -207,7 +207,9 @@ function theme_admin_page($variables) {
    + * Prepares variables for admin index template.
    

    "template" should be "templates" here per Preprocess function documentation standards.

  2. +++ b/core/modules/system/system.admin.inc
    @@ -215,55 +217,35 @@ function theme_admin_page($variables) {
    +    '#theme' => 'system_compact_link'
    

    Add a trailing comma here per https://drupal.org/coding-standards#array.

longwave’s picture

Status: Needs work » Needs review
Issue tags: -Novice
FileSize
4.02 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,117 pass(es), 1 fail(s), and 1 exception(s). View
1.84 KB

Fixed #20. Also removed one unneeded array key - 'blocks' was the only thing inside the container, so we don't need it - and two unnecessary blank lines.

joelpittet’s picture

RTBC++

Cottser’s picture

Status: Needs review » Reviewed & tested by the community

Nice, thanks @longwave! RTBC but it'll probably make sense for #2151089: Convert theme_admin_block() to Twig to get committed first. That last change to get rid of one level in the array should actually make the template faster too, one less call to \Twig_Template::getAttribute():

-            $context['_seq'] = twig_ensure_traversable($this->getAttribute((isset($context["container"]) ? $context["container"] : null), "blocks"));
+            $context['_seq'] = twig_ensure_traversable((isset($context["container"]) ? $context["container"] : null));
Cottser’s picture

Issue summary: View changes

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: 2151105-twig-system_admin_index-21.patch, failed testing.

longwave’s picture

longwave’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC, bot fluke:

Segmentation fault
FATAL Drupal\toolbar\Tests\ToolbarAdminMenuTest: test runner returned a non-zero error code (139).

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: 2151105-twig-system_admin_index-21.patch, failed testing.

Cottser’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
4.02 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,366 pass(es). View

Uploading the same (slightly different fuzz) patch as #21 so we can preserve the last testbot failure because a bunch of issues have had that same fail.

BTW, still probably makes sense to wait on #2151089: Convert theme_admin_block() to Twig before committing this one and then we can do a minor rework here. But either way works.

webchick’s picture

Status: Reviewed & tested by the community » Needs work

I did commit that one, so marking this one needs work.

joelpittet’s picture

Status: Needs work » Needs review
FileSize
4 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,297 pass(es). View

Re-rolled. Removed 'show'

joelpittet’s picture

diffed diffs:

--- from_file
+++ (clipboard)
@@ -1,8 +1,8 @@
 diff --git a/core/modules/system/system.admin.inc b/core/modules/system/system.admin.inc
-index 5789852..0e3cdcb 100644
+index 75f1c60..5fdfce0 100644
 --- a/core/modules/system/system.admin.inc
 +++ b/core/modules/system/system.admin.inc
-@@ -202,7 +202,9 @@ function theme_admin_page($variables) {
+@@ -150,7 +150,9 @@ function template_preprocess_admin_page(&$variables) {
  }
  
  /**
@@ -13,7 +13,7 @@
   *
   * @param $variables
   *   An associative array containing:
-@@ -210,55 +212,33 @@ function theme_admin_page($variables) {
+@@ -158,54 +160,32 @@ function template_preprocess_admin_page(&$variables) {
   *
   * @ingroup themeable
   */
@@ -46,7 +46,6 @@
 -      $block['title'] = $module;
 -      $block['content'] = drupal_render($admin_block_content);
 -      $block['description'] = t($description);
--      $block['show'] = TRUE;
 -
 -      $admin_block = array(
 +      $variables['containers'][$position][] = array(
@@ -55,7 +54,6 @@
 +        '#block' => array(
 +          'position' => $position,
 +          'title' => $module,
-+          'show' => TRUE,
 +          'content' => array(
 +            '#theme' => 'admin_block_content',
 +            '#content' => $items,
@@ -89,10 +87,10 @@
  
  /**
 diff --git a/core/modules/system/system.module b/core/modules/system/system.module
-index eef5bce..30da9fb 100644
+index ca908a2..b24428a 100644
 --- a/core/modules/system/system.module
 +++ b/core/modules/system/system.module
-@@ -209,6 +209,7 @@ function system_theme() {
+@@ -211,6 +211,7 @@ function system_theme() {
      'system_admin_index' => array(
        'variables' => array('menu_items' => NULL),
        'file' => 'system.admin.inc',
Cottser’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/templates/system-admin-index.html.twig
@@ -0,0 +1,24 @@
+ * - container: Container for admin blocks.
...
+  {% for position, container in containers %}
+    <div class="{{ position }} clearfix">
+      {% for block in container %}
+        {{ block }}
+      {% endfor %}
+    </div>
+  {% endfor %}

The docblock needs some updating to better document the containers (note plural) variable and what it contains (no pun intended). Search other .html.twig templates in core with {% for %} loops to see examples of how we document these.

joelpittet’s picture

Status: Needs work » Needs review
FileSize
4.12 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,427 pass(es). View

Doc updates.

Cottser’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/system.admin.inc
@@ -158,54 +160,32 @@ function template_preprocess_admin_page(&$variables) {
  * @ingroup themeable

Thanks @joelpittet that was quick!

I forgot to mention, we need to kill this @ingroup themeable. Related: #2219617: Remove @ingroup themeable from preprocess function docblocks

joelpittet’s picture

Status: Needs work » Needs review
FileSize
4.1 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,411 pass(es). View

I'm quick when I can smell RTBC:P

joelpittet’s picture

FileSize
695 bytes

interdiff between #34 and #36

Cottser’s picture

Status: Needs review » Needs work

We are definitely very very close to RTBC :)

+++ b/core/modules/system/templates/system-admin-index.html.twig
@@ -0,0 +1,26 @@
+ * - containers: A list of administrative blocks keyed by position: left or
+ *   right. Each container contains:
+ *   - blocks: A list of blocks within a container.
...
+  {% for position, container in containers %}
+    <div class="{{ position }} clearfix">
+      {% for block in container %}
+        {{ block }}
+      {% endfor %}
+    </div>
+  {% endfor %}

Sorry but I think the docs here are not quite 100% after giving them another read. At minimum 'blocks' in the docblock should be 'block' but I also think 'block' within a container is a single block not a list of blocks.

joelpittet’s picture

+++ b/core/modules/system/templates/system-admin-index.html.twig
@@ -0,0 +1,26 @@
+ * - containers: A list of administrative blocks keyed by position: left or
+ *   right. Each container contains:
+ *   - blocks: A list of blocks within a container.

Can we just remove from "Each container contains: ..."

The blocks are the containers.

Cottser’s picture

I guess what I'm zoning in on is "blocks" doesn't appear in the template at all. I'd suggest something along these lines:

+++ b/core/modules/system/templates/system-admin-index.html.twig
@@ -0,0 +1,26 @@
+ * - containers: A list of administrative blocks keyed by position: left or
+ *   right. Each container in the list contains:
+ *   - block: An administrative block, rendered through admin-block.html.twig.
joelpittet’s picture

I see that but block is just arbitrary name given to the value of the container. Maybe it would make more sense if we call the variable "containers" to "blocks" because all other ones were we do the "Each contains:" are properties on the object in the list. In this case the object is the "block" and it has no properties.

joelpittet’s picture

Status: Needs work » Needs review
FileSize
4.15 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 69,875 pass(es), 2 fail(s), and 0 exception(s). View
1.3 KB

Here's what I mean, took from your #40 but tried to make it make scents, cents, and sense.

Cottser’s picture

Status: Needs review » Reviewed & tested by the community

Should have gotten back to this sooner. New docs look good to me, thanks @joelpittet!

Patch still applies and I did another quick markup comparison and we still match up exactly.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 42: 2151105-twig-system_admin_index-42.patch, failed testing.

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
4.15 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 69,979 pass(es). View

Well that shouldn't have failed it still applies with git apply and patch -p1.

Here's a re-roll just in case. Thanks for RTBC @Cottser:)

  • Commit e8f1ce1 on 8.x by webchick:
    Issue #2151105 by Cottser, longwave, joelpittet: Convert...
webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed to 8.x. Thanks!

  • Commit 02a5887 on 8.x by webchick:
    Follow-up to Issue #2151105 : Helps if I commit the template file doesn'...

Status: Fixed » Closed (fixed)

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