Meta issue: #1843738: [meta] Convert views module to Twig
#1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch

Manual testing steps:

Testing unformatted lists with no grouping:

  1. Create some nodes
  2. Visit the front page - the default front page view is an unformatted list so compare this markup

Testing unformatted lists with grouping:

  1. Create some nodes
  2. Edit the default front page View
  3. Click "settings" for unformatted list and force fields on
  4. Add content titles as a field for this view
  5. Click "settings" for unformatted list again and select title as a field to group by
  6. Visit the front page - the default front page view should now be an unformatted list grouped by node titles

Comments

joelpittet’s picture

Status: Active » Needs work
StatusFileSize
new679 bytes

need a better way to deal with

<div {% if row_classes[id] %} class="{{ row_classes[id] }}"{% endif %}>

hopefully someone can point me to a way to get it like this:

<div class="{{ row.attributes.class }}"{{ row.attributes }}>
mbrett5062’s picture

Issue tags: +VDC

Tagging.

joelpittet’s picture

Project: » Drupal core
Version: » 8.x-dev
Component: Twig templates conversion (front-end branch) » theme system
Issue tags: +Twig

Moving to core queue

joelpittet’s picture

Assigned: Unassigned » joelpittet
Status: Needs work » Needs review
StatusFileSize
new3.76 KB

Preprocess needs a rewrite possibly but maybe a new issue for that, this is a straight conversion.

The preprocess docblock needs some love too I bet but lets see if this passes go.

star-szr’s picture

Title: Convert views/theme/views-view-unformatted.tpl.php to twig » Convert views/template/views-view-unformatted.tpl.php to twig

Re-titling.

star-szr’s picture

Issue tags: +Needs manual testing

Tagging.

joelpittet’s picture

Title: Convert views/template/views-view-unformatted.tpl.php to twig » Convert views/templates/views-view-unformatted.tpl.php to twig
joelpittet’s picture

Issue tags: +Novice

tagging

joelpittet’s picture

Issue tags: -Novice

untagging, just needs manual testing and code review.

joelpittet’s picture

StatusFileSize
new3.68 KB
new4.14 KB

Replaced {{ row_classes[id] }} with {{ row.attributes }}

Leaving $vars $variables because it doesn't obscure the patch much more than it would already be.

Added preprocess docblock from #1913208: [policy] Standardize template preprocess function documentation.

Status: Needs review » Needs work

The last submitted patch, twig-views-view-unformatted-1843770-10.patch, failed testing.

joelpittet’s picture

The above test failed due to views-view-list not having $row_classes.
I have sent in a VDC patch I hope to get in #1968398: Convert Views $row_classes to $row['attributes']

joelpittet’s picture

Status: Needs work » Needs review

Well I'm not waiting for that conversion to get in. Here is the straight conversion up for review. We can re-roll this if that get's in.

joelpittet’s picture

StatusFileSize
new3.82 KB
new5.09 KB

Did you forget an attachment joel? Why yes..., yes I did!

dawehner’s picture

Thanks for making it as simple as possible. Can't spot something fundamental, so all what's left is manual testing.

thedavidmeister’s picture

testing

thedavidmeister’s picture

View without groups (default front page).

Before:

<div  class="views-row views-row-1 views-row-odd views-row-first">
    <article id="node-2" class="node node-article promoted view-mode-teaser contextual-region clearfix" role="article" data-edit-entity="node/2" about="/d8raw/node/2" typeof="sioc:Item foaf:Document" role="article">

  <header>
              <h2 class="" property="dc:title" datatype="">
        <a href="/d8raw/node/2">lkajs ;ldfk asf</a>
      </h2>
        <ul class="contextual-links"><li class="node-edit odd first"><a href="/d8raw/node/2/edit?destination=node">Edit</a></li><li class="node-delete even last"><a href="/d8raw/node/2/delete?destination=node">Delete</a></li></ul>
          <div class="meta submitted">
        <article class="profile" class="user" typeof="sioc:UserAccount" about="/d8raw/user/1">
  </article>
        <span property="dc:date dc:created" content="2013-04-27T14:42:05+10:00" datatype="xsd:dateTime" rel="sioc:has_creator">Submitted by <a href="/d8raw/user/1" rel="author" title="View user profile." class="username" lang="" about="/d8raw/user/1" typeof="sioc:UserAccount" property="foaf:name" datatype="">admin</a> on Sat, 04/27/2013 - 14:42</span>      </div>
      </header>

  <div class="content clearfix" class="">
      </div>

      <footer class="link-wrapper">
      <ul class="links inline"><li class="node-readmore odd first last"><a href="/d8raw/node/2" rel="tag" title="lkajs ;ldfk asf">Read more<span class="element-invisible"> about lkajs ;ldfk asf</span></a></li></ul>    </footer>
  
  
</article>
  </div>
  <div  class="views-row views-row-2 views-row-even views-row-last">
    <article id="node-1" class="node node-article promoted view-mode-teaser contextual-region clearfix" role="article" data-edit-entity="node/1" about="/d8raw/node/1" typeof="sioc:Item foaf:Document" role="article">

  <header>
              <h2 class="" property="dc:title" datatype="">
        <a href="/d8raw/node/1">asdf</a>
      </h2>
        <ul class="contextual-links"><li class="node-edit odd first"><a href="/d8raw/node/1/edit?destination=node">Edit</a></li><li class="node-delete even last"><a href="/d8raw/node/1/delete?destination=node">Delete</a></li></ul>
          <div class="meta submitted">
        <article class="profile" class="user" typeof="sioc:UserAccount" about="/d8raw/user/1">
  </article>
        <span property="dc:date dc:created" content="2013-04-27T14:41:48+10:00" datatype="xsd:dateTime" rel="sioc:has_creator">Submitted by <a href="/d8raw/user/1" rel="author" title="View user profile." class="username" lang="" about="/d8raw/user/1" typeof="sioc:UserAccount" property="foaf:name" datatype="">admin</a> on Sat, 04/27/2013 - 14:41</span>      </div>
      </header>

  <div class="content clearfix" class="">
      </div>

      <footer class="link-wrapper">
      <ul class="links inline"><li class="node-readmore odd first last"><a href="/d8raw/node/1" rel="tag" title="asdf">Read more<span class="element-invisible"> about asdf</span></a></li></ul>    </footer>
  
  
</article>
  </div>

After:

<div  class="views-row views-row-1 views-row-odd views-row-first">
    <article id="node-2" class="node node-article promoted view-mode-teaser contextual-region clearfix" role="article" data-edit-entity="node/2" about="/d8html/node/2" typeof="sioc:Item foaf:Document" role="article">

  <header>
              <h2 class="" property="dc:title" datatype="">
        <a href="/d8html/node/2">laksjfdas</a>
      </h2>
        <ul class="contextual-links"><li class="node-edit odd first"><a href="/d8html/node/2/edit?destination=node">Edit</a></li><li class="node-delete even last"><a href="/d8html/node/2/delete?destination=node">Delete</a></li></ul>
          <div class="meta submitted">
        <article class="profile" class="user" typeof="sioc:UserAccount" about="/d8html/user/1">
  </article>
        <span property="dc:date dc:created" content="2013-04-27T15:47:44+11:00" datatype="xsd:dateTime" rel="sioc:has_creator">Submitted by <a href="/d8html/user/1" rel="author" title="View user profile." class="username" lang="" about="/d8html/user/1" typeof="sioc:UserAccount" property="foaf:name" datatype="">admin</a> on Sat, 04/27/2013 - 15:47</span>      </div>
      </header>

  <div class="content clearfix" class="">
      </div>

      <footer class="link-wrapper">
      <ul class="links inline"><li class="node-readmore odd first last"><a href="/d8html/node/2" rel="tag" title="laksjfdas">Read more<span class="element-invisible"> about laksjfdas</span></a></li></ul>    </footer>
  
  
</article>
  </div>
  <div  class="views-row views-row-2 views-row-even views-row-last">
    <article id="node-1" class="node node-article promoted view-mode-teaser contextual-region clearfix" role="article" data-edit-entity="node/1" about="/d8html/node/1" typeof="sioc:Item foaf:Document" role="article">

  <header>
              <h2 class="" property="dc:title" datatype="">
        <a href="/d8html/node/1">asdf</a>
      </h2>
        <ul class="contextual-links"><li class="node-edit odd first"><a href="/d8html/node/1/edit?destination=node">Edit</a></li><li class="node-delete even last"><a href="/d8html/node/1/delete?destination=node">Delete</a></li></ul>
          <div class="meta submitted">
        <article class="profile" class="user" typeof="sioc:UserAccount" about="/d8html/user/1">
  </article>
        <span property="dc:date dc:created" content="2013-04-27T15:47:30+11:00" datatype="xsd:dateTime" rel="sioc:has_creator">Submitted by <a href="/d8html/user/1" rel="author" title="View user profile." class="username" lang="" about="/d8html/user/1" typeof="sioc:UserAccount" property="foaf:name" datatype="">admin</a> on Sat, 04/27/2013 - 15:47</span>      </div>
      </header>

  <div class="content clearfix" class="">
      </div>

      <footer class="link-wrapper">
      <ul class="links inline"><li class="node-readmore odd first last"><a href="/d8html/node/1" rel="tag" title="asdf">Read more<span class="element-invisible"> about asdf</span></a></li></ul>    </footer>
  
  
</article>
  </div>

Inspecting the diff between these two looks good so far :)

thedavidmeister’s picture

Assigned: thedavidmeister » Unassigned
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs manual testing

With grouping of rows on the node title (modified front page):

Before:

 <h3>Title: <a href="/d8raw/node/2">lkajs ;ldfk asf</a></h3>
  <div  class="views-row views-row-1 views-row-odd views-row-first views-row-last">
    <article id="node-2" class="node node-article promoted view-mode-teaser contextual-region clearfix" role="article" data-edit-entity="node/2" about="/d8raw/node/2" typeof="sioc:Item foaf:Document" role="article">

  <header>
              <h2 class="" property="dc:title" datatype="">
        <a href="/d8raw/node/2">lkajs ;ldfk asf</a>
      </h2>
        <ul class="contextual-links"><li class="node-edit odd first"><a href="/d8raw/node/2/edit?destination=node">Edit</a></li><li class="node-delete even last"><a href="/d8raw/node/2/delete?destination=node">Delete</a></li></ul>
          <div class="meta submitted">
        <article class="profile" class="user" typeof="sioc:UserAccount" about="/d8raw/user/1">
  </article>
        <span property="dc:date dc:created" content="2013-04-27T14:42:05+10:00" datatype="xsd:dateTime" rel="sioc:has_creator">Submitted by <a href="/d8raw/user/1" rel="author" title="View user profile." class="username" lang="" about="/d8raw/user/1" typeof="sioc:UserAccount" property="foaf:name" datatype="">admin</a> on Sat, 04/27/2013 - 14:42</span>      </div>
      </header>

  <div class="content clearfix" class="">
      </div>

      <footer class="link-wrapper">
      <ul class="links inline"><li class="node-readmore odd first last"><a href="/d8raw/node/2" rel="tag" title="lkajs ;ldfk asf">Read more<span class="element-invisible"> about lkajs ;ldfk asf</span></a></li></ul>    </footer>


</article>
  </div>
  <h3>Title: <a href="/d8raw/node/1">asdf</a></h3>
  <div  class="views-row views-row-1 views-row-odd views-row-first views-row-last">
    <article id="node-1" class="node node-article promoted view-mode-teaser contextual-region clearfix" role="article" data-edit-entity="node/1" about="/d8raw/node/1" typeof="sioc:Item foaf:Document" role="article">

  <header>
              <h2 class="" property="dc:title" datatype="">
        <a href="/d8raw/node/1">asdf</a>
      </h2>
        <ul class="contextual-links"><li class="node-edit odd first"><a href="/d8raw/node/1/edit?destination=node">Edit</a></li><li class="node-delete even last"><a href="/d8raw/node/1/delete?destination=node">Delete</a></li></ul>
          <div class="meta submitted">
        <article class="profile" class="user" typeof="sioc:UserAccount" about="/d8raw/user/1">
  </article>
        <span property="dc:date dc:created" content="2013-04-27T14:41:48+10:00" datatype="xsd:dateTime" rel="sioc:has_creator">Submitted by <a href="/d8raw/user/1" rel="author" title="View user profile." class="username" lang="" about="/d8raw/user/1" typeof="sioc:UserAccount" property="foaf:name" datatype="">admin</a> on Sat, 04/27/2013 - 14:41</span>      </div>
      </header>

  <div class="content clearfix" class="">
      </div>

      <footer class="link-wrapper">
      <ul class="links inline"><li class="node-readmore odd first last"><a href="/d8raw/node/1" rel="tag" title="asdf">Read more<span class="element-invisible"> about asdf</span></a></li></ul>    </footer>


</article>
  </div>

After:

   <h3>Title: <a href="/d8html/node/2">laksjfdas</a></h3>
  <div  class="views-row views-row-1 views-row-odd views-row-first views-row-last">
    <article id="node-2" class="node node-article promoted view-mode-teaser contextual-region clearfix" role="article" data-edit-entity="node/2" about="/d8html/node/2" typeof="sioc:Item foaf:Document" role="article">

  <header>
              <h2 class="" property="dc:title" datatype="">
        <a href="/d8html/node/2">laksjfdas</a>
      </h2>
        <ul class="contextual-links"><li class="node-edit odd first"><a href="/d8html/node/2/edit?destination=node">Edit</a></li><li class="node-delete even last"><a href="/d8html/node/2/delete?destination=node">Delete</a></li></ul>
          <div class="meta submitted">
        <article class="profile" class="user" typeof="sioc:UserAccount" about="/d8html/user/1">
  </article>
        <span property="dc:date dc:created" content="2013-04-27T15:47:44+11:00" datatype="xsd:dateTime" rel="sioc:has_creator">Submitted by <a href="/d8html/user/1" rel="author" title="View user profile." class="username" lang="" about="/d8html/user/1" typeof="sioc:UserAccount" property="foaf:name" datatype="">admin</a> on Sat, 04/27/2013 - 15:47</span>      </div>
      </header>

  <div class="content clearfix" class="">
      </div>

      <footer class="link-wrapper">
      <ul class="links inline"><li class="node-readmore odd first last"><a href="/d8html/node/2" rel="tag" title="laksjfdas">Read more<span class="element-invisible"> about laksjfdas</span></a></li></ul>    </footer>


</article>
  </div>
  <h3>Title: <a href="/d8html/node/1">asdf</a></h3>
  <div  class="views-row views-row-1 views-row-odd views-row-first views-row-last">
    <article id="node-1" class="node node-article promoted view-mode-teaser contextual-region clearfix" role="article" data-edit-entity="node/1" about="/d8html/node/1" typeof="sioc:Item foaf:Document" role="article">

  <header>
              <h2 class="" property="dc:title" datatype="">
        <a href="/d8html/node/1">asdf</a>
      </h2>
        <ul class="contextual-links"><li class="node-edit odd first"><a href="/d8html/node/1/edit?destination=node">Edit</a></li><li class="node-delete even last"><a href="/d8html/node/1/delete?destination=node">Delete</a></li></ul>
          <div class="meta submitted">
        <article class="profile" class="user" typeof="sioc:UserAccount" about="/d8html/user/1">
  </article>
        <span property="dc:date dc:created" content="2013-04-27T15:47:30+11:00" datatype="xsd:dateTime" rel="sioc:has_creator">Submitted by <a href="/d8html/user/1" rel="author" title="View user profile." class="username" lang="" about="/d8html/user/1" typeof="sioc:UserAccount" property="foaf:name" datatype="">admin</a> on Sat, 04/27/2013 - 15:47</span>      </div>
      </header>

  <div class="content clearfix" class="">
      </div>

      <footer class="link-wrapper">
      <ul class="links inline"><li class="node-readmore odd first last"><a href="/d8html/node/1" rel="tag" title="asdf">Read more<span class="element-invisible"> about asdf</span></a></li></ul>    </footer>


</article>
  </div>

I've inspected the diff and everything looks good here.

That should be it for manual testing. I'll update the issue summary with steps to replicate what I've done.

thedavidmeister’s picture

Issue summary: View changes

added manual testing steps

star-szr’s picture

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

Nice work on this @joelpittet, and thank you @thedavidmeister for the thorough manual testing!

Found some tiny documentation tweaks and I think we should roll back the vars -> variables change for now and leave it for #1963942: Change all instances of $vars to $variables - at a glance it looks like we could leave the 'body' of the preprocess function untouched if we revert that.

Rolling back the vars -> variables change and making the below tweaks (posting a new patch and interdiff) would be a good novice task, tagging. After this I'd say it's back to RTBC :)

  1. +++ b/core/modules/views/templates/views-view-unformatted.html.twigundefined
    @@ -0,0 +1,24 @@
    + * Variables available:
    

    'Available variables:' per http://drupal.org/node/1823416#docblock.

  2. +++ b/core/modules/views/templates/views-view-unformatted.html.twigundefined
    @@ -0,0 +1,24 @@
    + * @file
    + * Default simple View template to display a list of rows.
    

    Should start with 'Default theme implementation…' per http://drupal.org/node/1823416#docblock. Maybe something different along the lines of 'Default theme implementation to display a View of unformatted rows.'? (the whole line needs to fit in 80 characters per http://drupal.org/node/1354#file)

  3. +++ b/core/modules/views/templates/views-view-unformatted.html.twigundefined
    @@ -0,0 +1,24 @@
    + * - row_classes: A list of row class attributes keyed by the row's id.
    

    capitalize ID.

  4. +++ b/core/modules/views/templates/views-view-unformatted.html.twigundefined
    @@ -0,0 +1,24 @@
    + * @ingroup themable
    

    @ingroup themeable (add e)

  5. +++ b/core/modules/views/views.theme.incundefined
    @@ -788,42 +788,49 @@ function template_preprocess_views_view_grid(&$vars) {
    + *   - rows: @todo.
    

    Do we have this documented in another Views patch that we can copy + paste? :) [check other issues in #1843738: [meta] Convert views module to Twig]

  6. +++ b/core/modules/views/views.theme.incundefined
    @@ -1111,7 +1118,7 @@ function theme_views_mini_pager($vars) {
    - * The default style for all views is views-view-unformatted.tpl.php
    + * The default style for all views is views-view-unformatted.html.twig
    

    Might as well add a period here per http://drupal.org/node/1354#drupal.

izus’s picture

StatusFileSize
new4.06 KB
new3.18 KB

Hi,
taking into account the feedback in #19.
Thanks

izus’s picture

Status: Needs work » Needs review

status

thedavidmeister’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Novice
star-szr’s picture

Changes look great, thanks @izus :)

star-szr’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/views.theme.incundefined
@@ -791,7 +791,14 @@ function template_preprocess_views_view_grid(&$vars) {
+ * @param array $variables
...
 function template_preprocess_views_view_unformatted(&$vars) {

Unfortunately we'll need to change the @param to say '@param array $vars' for now.

thedavidmeister’s picture

Issue tags: +Novice
izus’s picture

Status: Needs work » Needs review
StatusFileSize
new685 bytes
new3.17 KB

Hi,
fixed #24.
Thanks

joelpittet’s picture

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

Thanks @izus back to RTBC

joelpittet’s picture

Issue summary: View changes

Updated issue summary.

star-szr’s picture

Issue tags: +needs profiling

Tagging for profiling.

joelpittet’s picture

Issue tags: -needs profiling
StatusFileSize
new1.6 KB
new3.17 KB

doc updates V to v.

joelpittet’s picture

Issue tags: +needs profiling

re-tagging

jerdavis’s picture

Assigned: Unassigned » jerdavis
jerdavis’s picture

Assigned: jerdavis » Unassigned
Issue tags: -needs profiling

Scenario

* Ensured front page view was using unformatted list
* Added 50 nodes with devel generate
* Placed a block with a full node on front page
* Ran scenario multiple times, most common result below

=== 8.x..8.x compared (519ac49c4babd..519ac4e8a277a):

ct  : 69,517|69,517|0|0.0%
wt  : 303,275|302,359|-916|-0.3%
cpu : 290,987|288,919|-2,068|-0.7%
mu  : 15,241,336|15,241,336|0|0.0%
pmu : 15,448,640|15,448,640|0|0.0%

<a href="http://drupal8/xhprof-kit/xhprof/xhprof_html/index.php?source=drupal-perf&url=%2F&run1=519ac49c4babd&run2=519ac4e8a277a&extra=8.x..8.x">Profiler output</a>

=== 8.x..1843770-twig-views-view-unformatted compared (519ac49c4babd..519ac503c625d):

ct  : 69,517|69,733|216|0.3%
wt  : 303,275|301,827|-1,448|-0.5%
cpu : 290,987|290,652|-335|-0.1%
mu  : 15,241,336|15,271,496|30,160|0.2%
pmu : 15,448,640|15,479,696|31,056|0.2%
alexpott’s picture

Title: Convert views/templates/views-view-unformatted.tpl.php to twig » [READY] Convert views/templates/views-view-unformatted.tpl.php to twig
Status: Reviewed & tested by the community » Closed (duplicate)
jerdavis’s picture

Uploaded results

=== 8.x..8.x compared (519ac3111f5a8..519ac33fa2f04):

ct  : 69,517|69,517|0|0.0%
wt  : 302,345|302,919|574|0.2%
cpu : 290,653|289,636|-1,017|-0.3%
mu  : 15,241,336|15,241,336|0|0.0%
pmu : 15,448,640|15,448,640|0|0.0%

http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519ac3111f5a8&run2=519ac33fa2f04&source=drupal-perf-drupalcon&extra=8.x..8.x

Run 519ac3111f5a8 uploaded successfully for drupal-perf-drupalcon.
Run 519ac3890abbd uploaded successfully for drupal-perf-drupalcon.
=== 8.x..1843770-twig-views-view-unformatted compared (519ac3111f5a8..519ac3890abbd):

ct  : 69,517|69,733|216|0.3%
wt  : 302,345|300,875|-1,470|-0.5%
cpu : 290,653|288,995|-1,658|-0.6%
mu  : 15,241,336|15,271,496|30,160|0.2%
pmu : 15,448,640|15,479,696|31,056|0.2%

http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519ac3111f5a8&run2=519ac3890abbd&source=drupal-perf-drupalcon&extra=8.x..1843770-twig-views-view-unformatted
alexpott’s picture

Title: [READY] Convert views/templates/views-view-unformatted.tpl.php to twig » Convert views/templates/views-view-unformatted.tpl.php to twig
Status: Closed (duplicate) » Fixed

Committed 6880348 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.