Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
theme system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
10 Mar 2013 at 22:59 UTC
Updated:
29 Jul 2014 at 22:01 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #0.0
star-szrAdding sandbox issue to related issues
Comment #1
jenlamptondibbs
Comment #1.0
jenlamptonAdding link to ol/ul issue
Comment #2
jenlamptonHere's my first attempt!
It currently moves the item-list class onto the UL tag (but still leaves the item-list class on the surrounding div tag so CSS in core won't break). Also, whitespace in the rendered HTML is a little funny, but I spent about a half hour fighting with the whitespace controllers and am officially giving up here. Open to feedback :)
Comment #2.0
jenlamptonupdate required actions
Comment #2.1
jenlamptonr
Comment #4
joelpittet@jenlampton That's a great start, could you add your twig file to that patch above?
Comment #5
jenlamptonhahahahaha :) yes.
Comment #6
joelpittetOk well here's a stab at that twig template. @jenlampton maybe you can merge what you have?
The interdiff on the twig is not quite right because there wasn't one and I added it from sandbox or someplace.
May still fail but, better. I think I was having some
"attributes" is an invalid render array keyissues but didn't see that in the array coming in...Comment #7
joelpittetwhoops, remove debug... but that debug is what I was checking to see what's up with attributes... so if you are curious and it fails, use the above patch.
Comment #9
steveoliver commentedAttached patch does a few things to get tests passing:
1. Whitespace control.
2. Disables the default class added by template_preprocess (from #1938430: Don't add a default theme hook class in template_preprocess())
3. Uses #wrapper_attributes of each item (which are render arrays and must stay #-prefixed so render() doesn't complain about "invalid render element".
If this passes all tests, then so too will #1938430: Don't add a default theme hook class in template_preprocess(), which should be committed asap as it's causing problems in other conversion issues.
Comment #11
steveoliver commentedThis should pass, as it includes all the changes that make #1938430: Don't add a default theme hook class in template_preprocess() pass.
Comment #13
steveoliver commentedThis patch:
1. Whitespace
2. Render arrays
should fix most if not all fails.
Comment #14
joelpittetNice getting this to pass @steveoliver!
No way around this? :S
Comment #15
steveoliver commentedNope, this is what we've got to do, and I think it's a fine enough 'exception' to deal with in order to have child items as render arrays. See #891112-78: Replace theme_item_list()'s 'data' items with render elements.
Attached patch just simplifies the comment in the template.
Comment #17
steveoliver commentedI don't know if that was a fluke -- it appears to be new. Testing again...
Comment #18
steveoliver commented#15: drupal-twig-item-list--1939062-15.patch queued for re-testing.
Comment #19
star-szrThis is looking good! Quick docs review:
s/Preprocesses/Prepares
Capitalize 'remove'.
These don't match the formatting for @see, notably the comments after the URL. @see http://drupal.org/node/1354#see :)
Comment #20
steveoliver commentedOK, Updated docs as per Cottser's suggestions in #19, and went through the .html.twig docblock and cleaned that up too. In the process, I added a @see to the change record #1842756: theme_item_list()'s $items variable are either strings or render arrays now -- don't know if that's what we want -- it may get outdated at some point. Figured it doesn't hurt for now, though, esp. since theme_item_list has changed so much.
The "-clean" patch should be committed after #1938430: Don't add a default theme hook class in template_preprocess() lands. The "-temp" one includes the changes from that patch to pass tests for the time being.
Assigning to myself for fame and glory.
Comment #21
jenlamptonThanks for all this awesome work :) I'm going to create a follow-up issue so we can get rid of the funky syntax:
There's two things here that are big no-nos for the new theme layer: the array-like syntax and also the hash in the key. It seems like we should be able to do something a little smarter with Twig and its object's __to_strings to take care of attributes on items in loops. I've been thinking about this in a few other similar issues too, but it's a follow-up for sure.
Follow-up: #1963402: Pass variables to Twig in a nicer way (was: Create drillable render arrays)
Comment #22
star-szrWe could consider Twig's attribute function, but it could get confusing with Drupal's Attribute object in the mix, and of course this wouldn't be needed if it weren't for the hash in the key.
<li{{ attribute(item, '#wrapper_attributes') }}>{{ item }}</li>Edit: remove quotes from 'item'.
Comment #23
thedavidmeister commentedHaving a look at #20:
Why do we touch comment.module and block.module in this patch?
+{% if items is not empty %}Is there a reason for the "is not empty" style conditionals in the template or would {% if foo %} suffice?
Anyway, from a coding standards perspective this patch looks good to me. Nice work everyone :)
This patch is probably ready for somebody to manually test the markup after updating the issue summary to provide manual testing steps.
Comment #24
star-szrThanks @thedavidmeister!
Now that the #1938430: Don't add a default theme hook class in template_preprocess() is postponed, the -clean.patch should be reworked so that we remove the offending class in the preprocess function, that way the markup matches up and tests pass.
Comment #25
steveoliver commentedAdded workaround for default item-list class while #1938430: Don't add a default theme hook class in template_preprocess() is postponed. I don't know what we'd manually test here that isn't covered by testItemList(), so removing the tag.
Comment #26
steveoliver commentedAlso, the patch in #25 addresses David's point from #23, the is not empty check is not necessary -- it has been removed.
Comment #27
jenlamptonreviewing, and see some little problems. Will do a quick re-roll here.
Comment #28
jenlamptonchanges:
- we decided way back when that HTML tags themselves should not be variables. We can use the variable to choose which HTML tag gets printed, but we should not create the HTML tag by printing that variable in the template. It's messy from a coder perspective, but this kind of output will make a lot more sense to someone looking for a UL tag or an OL tag in their HTML output:
- the variable named tag. I changed this originally to type, since there are lots of tags being output in the template, but there's now a note in here that type conflicts with '#type' in render arrays. If that's really the case (i haven't had a problem with it but that doesn't mean it's not a real problem) then how about a name like list_type. Since it's not a variable to be printed anymore, but instead a variable to be tested, something that more clearly indicates what is being tested makes more sense here.
- changed @see to @todo with a description of what needs to be done. If we decided not TODO this then we can remove this comment later.
- I'm not sure why there's an @see to the change record in the preprocess docblock. Is this a new standard for us? (leaving as-is until I understand more)
I think this is looking great :) Good work team!
Comment #28.0
jenlamptonr
Comment #30
star-szrThis just combines #25 with the interdiff from #28. Go team indeed :)
Comment #31
jenlamptonThanks Cottser! I really want to review this, but it still feels too much like reviewing my own patch. Any takers? :)
Comment #32
thedavidmeister commented#31 - I'm planning to do a bunch of reviews this weekend. It might turn up on my radar then if nobody gets there first..
Comment #32.0
thedavidmeister commentedrm sand
Comment #33
c4rl commentedRelated #1828536: Rename 'type' variable of theme_item_list() to 'list_type'
Comment #34
c4rl commentedSeems like we should change the test instead.
Comment #35
c4rl commented#wrapper_attributes seems ugly to me, but I'm not sure we have a way around it in the short-term.
I simplified some of the markup for the test.
Interdiff with respect to #30.
Comment #36
jenlamptonThe tests look much beter, thanks @C4rl!
Unfortunately, the patch in #35 still generates a HTML tag by printing a variable, and that needs to be fixed. (see comment in #28)
Comment #37
jenlamptongivin' it another go.
Patch contains
- passing tests (but added a newline to get them passing)
- actual UL and OL tags instead of printing a variable
- changed 'type' back to 'list_type' form 'list_tag'
I could go either way on the 3rd one, but I did reroll the patch over at #1828536: Rename 'type' variable of theme_item_list() to 'list_type' to use list_type as well.
Comment #38
star-szrMinor coding standards tweak:
Comment #39
jwilson3This patch is extremely difficult to read and review because of seemingly randomly placed pieces of code from the preprocess function being interspersed inside the removed theme_item_list. Weird. Oh, well.
Do we need two @see's here?DOH, they reference different nodes ;) so yes.I've seen elsewhere where people are only using {% if foo %} but admittedly, don't understand why or when the "is not empty" part is ever necessary.
Comment #40
thedavidmeister commented#39 - The "is not empty" part should no longer be required so we should remove it. This is something that was needed in some cases before #1975442: drupal_render() should always return a string. and #1975462: Allow and test for NULL and integer 0 values in Twig templates. landed.
Comment #41
star-szr#39/@jwilson3 - For reviewing patches like this one that change (parts of) big theme functions, I recommend applying the patch locally and looking at the preprocess function in your editor or diff tool of choice :) I ran into the same thing on a few other patches.
Comment #42
star-szrRemoved the 'is not empty', removed a #dreammarkup @todo, and tweaked the docs some.
Usually we indent the contents of if blocks - are we making an exception here or do we want to modify the tests a bit more (we're already modifying them and it's just whitespace changes)?
Comment #43
cellearComment #44
jenlampton@Cottser can we leave the @todo in there? We don't want D8 to ship without that change so leaving it in will keep reminding us, as long as there's a link to the issue that needs to be resolved I think it's okay (but correct me if you know different).
I'm fine with updating the whitespace and updating the tests, too. :)
I know @cellear is testing, so I'm going to leave at needs review, but @cellear please set to 'needs work' when you are done testing the patch?
Comment #45
star-szr@jenlampton - From my understanding adding @todos at this point in the release cycle moves us further from release. Committers will be reluctant to commit anything with a @todo in it. In this case we would risk the template shipping with a @todo in it which is an easy risk to avoid :)
Setting to needs work for the if block indent/test update proposed in #42, I think that can proceed along with testing - manual testing I assume?
Comment #46
cellearMy first patch review.
- I see the changed documentation, the removed @todo, and the more concise "if not empty" statement in the patches.
- I verified the changes in core/includes/theme.inc and core/modules/system/templates/item-list.html.twig.
- I applied https://drupal.org/files/1939062-38.patch and https://drupal.org/files/1939062-42.patch to virgin downloads of d8 (commit 7a0440d196e754d629ab42ada27f26bf4d7916ee - Wed Jun 19 01:44:06 2013 +0200) and compared the output for admin/modules/list/confirm when adding Views UI (which generates this item list output:
I verified that each of the three patch states (unpatched, 1939062-38, and 1939062-42) generated identical output.
It all seems to work as advertised, so I'm marking this "RTBC." Future patch tests will probably be less wordy :)
Comment #47
cellearComment #48
cellearChanging status to 'needs work' per #44
Comment #49
star-szrThis needs profiling as well.
Thanks for the review @cellear, I think you were quite thorough :)
Comment #50
star-szrAnd Novice tagging for updating the if indent and associated tests as described in #42.
Comment #51
pwieck commentedSince this needs rework remove @see template_preprocess()
[policy adopted, patch needed] Stop saying '@see template_preprocess()' in every twig file
What?... I just stated a policy. :-p
I submitted a patch to correct the exiting ones.
Comment #52
gabesulliceThis is my first patch (thanks to some Drupal ladder mentors at Aten Design). I indented the if blocks as I assume you were needing it done. Wasn't sure what needs to be done for the "associated tests" as mentioned in #50.
We had a small question related to the for loop. Not sure how best to do that, but this is our best attempt.
Feedback much appreciated. Thanks!
Comment #53
pwieck commentedchanging status
@gabesullice @see template_preprocess() needs to be removed see policy change in #51.
Comment #54
joelpittet#52 Thank you @gabesullice. The associated tests are if the tests are checking whitespace they will fail after indent so they would need to be changed to add the space in the tests as well, or better yet, use xpath and ignore whitespace differences.
To get the patch to get tested you need to set the status to needs review. I'm doing that for you here. I usually forget to do that often as well.
Comment #56
hussainwebTrying again... I just added
{% spaceless %}in the twig file so that we don't have to account for whitespace in tests. I also removed@see template_preprocessas per #53.Comment #57
hussainwebComment #57.0
hussainwebAdd type/tag issue to summary
Comment #58
jenlamptonRerolled, removed @todo now that this landed: #1938430: Don't add a default theme hook class in template_preprocess()
Comment #60
joelpittetThis should be removed and let the issue deal with it.
These are lazy loaded so not needed here.
Comment #61
star-szrCrosspost with testbot.
Comment #62
drupalninja99 commentedNot sure why Jen's patch failed but it did need a re-roll. I re-rolled it and then added Joel's 2 changes from #60. I am re-submitting for review
Comment #64
hussainwebThe problem was this block of code:
This was kind of a workaround for #1828536: Rename 'type' variable of theme_item_list() to 'list_type'. Since that fix got in, this was not necessary and in fact, it overwrote the correct variable. I have removed this block, as seen in interdiff. I also ran one of the failing tests and it passed. Lets see what the testbot thinks.
Comment #65
star-szrNeeds another reroll.
Comment #66
hussainwebRe-rolled
Comment #67
joelpittetremoving tags. Thanks @hussainweb for the re-roll!
Comment #68
joelpittetProfiling this...
Comment #69
joelpittetScenario:
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5206d663ca0ba&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5206d663ca0ba&...
Comment #70
webchickHm. That's quite a bit more of a jump compared to other Twig conversions. Since this is a very user-facing theme bit which is used basically everywhere, tentatively assigning to catch to give final approval.
Comment #71
catchLooks from the profiling data like this is the change from three calls rather than one, but yeah it's still quite a big jump. Still thinking about this one a bit sorry for the delayed update.
Comment #72
star-szr+0.2% wt doesn't seem that much to me, but it sounds like more data might be useful (with more item_list's)?
Comment #73
catch0.2% wall time is only not much because the total wt for the request was over 500ms - and 500ms is a depressing figure for a simple-ish page.
What I'm really looking at is the ms difference, which is about 1.5ms, and the function calls which is +797.
Drupal 7 can serve fairly simple pages in around 100ms (obviously depends on a lot of things), but in that context 1.5ms is 1.5% which is not small for three theme() calls.
It would be handy to do a more targeted test I think - marking back to CNR and unassigning for that.
Comment #74
star-szrSure, I will see what I can do.
Comment #75
star-szrUnassigning since I haven't touched this in over 2 weeks - I do have a couple long flights coming up though ;)
Comment #76
star-szrLooking at this today.
Comment #77
star-szrHere are the results for 11 item lists instead of 3, so this seems a bit high. Perhaps we need to do something similar to #1939102: Convert theme_indentation() to Twig here :/
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5240420daae43&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5240420daae43&...
Comment #77.0
star-szrrelated
Comment #78
joelpittet66: theme_item_list-1939062-66.patch queued for re-testing.
Comment #80
dale42Comment #81
dale42Patch failed because of #2120807: Add empty option to item_list.
Added the new 'empty' variable to the twig template. Also fixed docblock inconsistency with list_type parameter name.
Comment #82
dale42Patch failed because of #2120807: Add empty option to item_list.
Added the new 'empty' variable to the twig template. Also fixed docblock inconsistency with list_type parameter name.
(Resubmitted w/patch)
Comment #83
dale42Comment #84
dale42Comment #86
joelpittet82: theme_item_list-1939062-82.patch queued for re-testing.
Comment #88
joelpittetThe patch looks right, though the test fails are related to the empty variable. I'd put my money on whitespace errors as some tests are testing whitespace you may need those minus sign whitespace operators to fix this.
{%- {{-Comment #89
ekl1773@JesseBeach and I had a whack at those testbot errors. Running Drupal\system\Tests\Theme\FunctionsTest in Simpletest on my local install also threw a few more errors from "testLinks()", which are as yet unresolved. I'm uploading what we came up with and an interdiff to keep this moving along.
Mostly we removed {% spaceless %}, added some more whitespace operators, and moved the
Comment #90
joelpittet@ekl1773 thanks for moving this along! Hoping it'll come back green. There is a twig coding standard to indent the code after the if statement... though personally if the output looks cleaner I'd like to disregard that:)
Also, thanks for removing spaceless! We'd rather the tests no require the whitespace and if possible make the output as easy to read as possible over conforming the output to match the tests when it comes to whitespace which the browser doesn't care. Obviously if the space is required for separating two inline things it's important but otherwise it really doesn't matter.
*crosses fingers for green*
Comment #92
joelpittet89: theme_item_list-1939062-89.patch queued for re-testing.
Comment #93
joelpittetThose tests pass locally so I'm calling BS on testbot for now...
Comment #95
star-szr89: theme_item_list-1939062-89.patch queued for re-testing.
Comment #96
joelpittetLatest profiling on #89
Scenario:
Bartik theme
4 Aggregator feed blocks
3 recent comment blocks
1 Who's new block
1 Who's online block
1 views pager item list
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52a03729e7d1a&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52a03729e7d1a&...
Comment #97
joelpittetCan we somehow get away with not having the #wrapper_attributes? Other than that this is good to go.
Comment #98
star-szrTagging for reroll.
Comment #99
jerdavisRe-roll of #89
Comment #102
rainbowarrayDid another reroll. I pulled out the wrapper_attributes on this one, both in the Twig file and in the code where those were set in the preprocess function. I also saw that element_children was deprecated, so I replaced it with Element::children and added the Use statement for the class at the top of theme.inc.
Comment #103
rainbowarrayAfter further discussion with Cottser on IRC, we need to leave item['#wrapper_attributes'] in the Twig file so that modules can add classes if necessary. I did pull out the first/last/odd/even code in the preprocess function, along with $i and $num_items, which were no longer needed. Hopefully this goes green!
Comment #104
star-szrThanks!
I think we can ditch these lines since #1649780: Remove first/last/odd/even classes in favor of CSS3 pseudo selectors is in (as you alluded to above @mdrummond), but at the same time I think we may be losing too much of theme_item_list, more specifically I'm not seeing where the li attributes are being set up in preprocess.
Comment #105
star-szrAnd as we talked about, this could be follow-up but it may also make sense to do here, something along these lines:
Then in the Twig template something like this:
Comment #109
rainbowarrayStrange. I must have messed something up with the last patch as I didn't intend to pull out the wrapper_attributes code, and I did intend to pull out the num_items.
So.
Here's another revised version that may or may not be correct. I provided an interdiff. We'll see if it works!
Comment #110
rainbowarrayComment #112
rainbowarrayI guess I'm at least consistent in increasing the failure rate on my patches.
Comment #113
joelpittet@mdrummond try a few of these to see how things will fair.
This should happen all the time, not only when the item is not an array. Just remove the else block around it.
This bit is key to have the attributes show up. Add it back in.
This is not needed, it should be the same but for #wrapper_attributes.
Remove the space before the item.attributes, it prints a space before each attribute so it just adds 2 at the start.
Comment #114
rainbowarrayHere's a new version of the patch with suggested changes.
Comment #116
joelpittet@mdrummond headway! Only 6 fails/exceptions on one test. You are so close!
There are a couple nitpicks but I'll wait till green as code will change.
Comment #117
rainbowarrayAny suggestions on what needs fixing?
Comment #118
joelpittet@mdrummond It's not evident, you may have to find out by running the failed test locally.
The test is \Drupal\views_ui\Tests\UI\FieldUITest
If you run debug($this->content); in the testFieldUI function. You can see the item list on the page in the test results. That way you can possibly see what went wrong.
Before and after the patch markup should give you hints.
The xpath test are looking inside the LI tags for some text like "[age] == Age" or "[id] == ID"
If you aren't familiar with xpath it's like old school DOM query language (like CSS)
//details[@id="edit-options-alter-help"]/div[@class="details-wrapper"]/div[@class="item-list"]/fields/liis like
details[#id="edit-options-alter-help"] > div.details-wrapper > div.item-list > fields > liWhich now that I explain that bit to you...
change this to
Because
<fields>Comment #119
joelpittetAnd my nitpickery after that passes.
Don't need the is_array() check here. It wasn't used before, and we already expect it to always be an array.
instead of "Store item ..."
Combine thes to something like:
"Set the item's value and attributes for the template" or something. Note not 'Twig' is the key here.
Also instead of mixing array access just define them together.
Comment #120
rainbowarrayHere's another patch with Joel's suggestion. Go, green, go!
Comment #121
star-szrWoo! Setting to needs review for the bot.
Comment #122
rainbowarrayOh wow, green!
Comment #123
joelpittetHell ya and the the markup is clear now too, no '#wrapper_attributes' or extra nested if statements. Nice work @mdrummond.
I don't think this needs markup review again, mostly because the tests do a good job of finding things on this one. But it does need another round of profiling (should be faster with less whitespace modifiers and conditions), and twig 1.15 is just faster.
@mdrummond you're welcome to give that a crack if you want, just assign yourself for that?
https://drupal.org/contributor-tasks/profiling
What ever profiling is done I'll likely run another one with the same scenario just to compare results.
Comment #124
rainbowarrayI've never doing profiling before, but I can try to learn that this weekend with the link you provided. Should be able to get started tonight.
Comment #125
rainbowarrayWith Cottser's help and several hours of work, I was finally able to get profiling to work, and to work well for this patch.
For the scenario, I used Bartik and had nine user login blocks in different areas of the page.
Here are the results:
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52f2e60305388&...
Run 52f2e60305388 uploaded successfully for drupal-perf-drupalcon.
Run 52f2e62cef49a uploaded successfully for drupal-perf-drupalcon.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52f2e60305388&...
Comment #126
joelpittet@mdrummond awesome work, thanks for profiling! it does take a lot of time!
I did one to compare and it's different but also not bad. Let's mark this RTBC:)
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52f30aadf2c65&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=52f30aadf2c65&...
Comment #127
star-szrComment #128
webchickCommitted and pushed to 8.x. Thanks!
Comment #129
star-szrI'm going to open a follow-up issue to fix the empty text logic and add test coverage, the logic here is not quite right.
Comment #130
joelpittetI'll follow that follow-up! Yeah just realized it is a bit off too.
Comment #131
jhodgdonWe may want to consider reverting this instead, as it isn't really right? And where's the follow-up?
Comment #132
star-szrSorry, forgot to comment here. It's a really small follow-up, just needs testbot approval and someone to OK it.
#2191323: item-list.html.twig always shows empty text