Meta issue: #1843738: [meta] Convert views module to Twig
Meta meta issue: #1757550: [Meta] Convert core theme functions to Twig templates
#1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch
Manual testing steps:
1. Add an article
2. Look at the front page view.
| Comment | File | Size | Author |
|---|---|---|---|
| #108 | 1843744-108.patch | 16.22 KB | socketwench |
| #105 | 1843744-105.patch | 16.22 KB | star-szr |
| #105 | interdiff.txt | 1.62 KB | star-szr |
| #101 | twig-views-view-1843744-101.patch | 16 KB | hydra |
| #101 | interdiff.txt | 1.98 KB | hydra |
Comments
Comment #1
joelpittetSeparated from meta with attributes.class added
Comment #2
aspilicious commentedBe carefull wth trailing whitespaces. There are 2 of them
Comment #3
mbrett5062 commentedTagging.
Comment #4
tsi commentedComment #5
joelpittetThanks for cleaning up my extra spaces, is there anything else you changed? @tsi
Comment #6
tsi commentedNope, just that.
Comment #7
mbrett5062 commentedJust a little nitpicking, otherwise good to go I think.
Documentation lines should end with a period.
css_class description should read 'class' not 'classes.
Comment #8
tsi commentedComment #9
mbrett5062 commentedExcellent @tsi, this is complete now AFAICT. Not marking RTBC though, as I have no idea how to test manually. Leave that for someone else.
Comment #10
fluxsauce commentedCommitted. My apologies for messing up the attribution #8, was trying to reconcile a large number of patches and I had a stupid.
Comment #11
fluxsauce commentedComment #13
joelpittetMoving to core queue
Comment #14
joelpittetMoved over to the right place for core, replaced all the is defined with just {% if var %} because that should be closer and
strict_variablesis turned off anyway so I don't think 'is defined' does much.I don't think this will pass all tests and may need to change some tests but it will get this party started...
Comment #16
joelpittetComment #17
joelpittet#14: twig-views-view-1843744-14.patch queued for re-testing.
Comment #18
joelpittetremoved the
lengthbit and cleaned up some docs.Comment #20
joelpittetThere are two fails I can see. They are to do with TwigReference with an empty string not evaluating as empty.
Comment #22
joelpittetOk @Cottser helped me, not sure how this fixed things... but it worked!
Comment #23
dawehnerShould be probably "Default theme implementation for main view template."
The indentation seems to be too much. I guess 3 spaces could be better.
I'm wondering when we should use "if foo is not empty" and when just "if foo". Would be cool just that I can understand it.
To be honest I'm sad about the variables conversions in this issues, as this causes bike-shedding, rerolling of other patches etc.
Comment #24
star-szrCan we convert core/modules/views/templates/views-view--frontpage.tpl.php here as well? Seems rather similar and I don't think we have an issue covering that one. If it doesn't make sense to do as part of this issue we can create a new issue for it.
I think for the $vars -> $variables we could probably leave those, but if we're changing the lined up assignments and so on, I'm not sure where we draw the line.
Comment #25
joelpittet@dawehner Thanks for the doc help first.
The biggest difference for twig if's is:
{% if rows is not empty %}is different with 0 and '0' beingTRUEand those would be FALSE with{% if rows %}so in this case your right, it's not needed because that is usually an array or empty array and will be treated the same for both cases.So if you expect a 0/'0' then check with 'is not empty':)
Can you point to the issues that are causing re-rolls due to $vars to $variables conversion? Should create issues for these fixes? Why would this be a bikeshed if $variables is the standard for the rest of core? I don't mind reverting these, just wonder where people are having issues. I sympathize with @Cottser, the line is gray.
Added doc changes and not empty changes from #23 and views-view--frontpage from #24
Comment #26
dawehnerThat's cool. Thanks for guiding me in twig!
That has been just a general statement, but yeah let's better just do it here, and if something needs a rerole, it needs a rerole. Let's be pragmatic here.
Good catch with the template file! So i'm wondering about the following: doesn't twig support inheritance of template files? Would this allow us here to pust reference the other file, and that's it? This would reduce the maintenance overhead a bit.
Comment #27
star-szrTagging.
Comment #28
joelpittetComment #29
star-szr@dawehner - I think the answer to your question "doesn't twig support inheritance of template files [in core]" from #26 is: Maybe later :)
Comment #30
jenlampton@Cottser @dawehner I've moved this issue from our sandbox to the core queue: #1783184: [meta] Use Twig template inheritance Hopefully we can't forget to revisit inheritance before D8 ships. :)
I also added a note about test modules, but I'm not sure that's a good use case for inheritance. Codeblocks for the sake of testing seem, overkill.
Also, testing this one manually for you.
Comment #31
jenlamptonIt looks like the only difference here is that we add four extra new-lines in the Twig version. But either way, there are way too many new-lines :) I'm going to clean some of these out and do a quick re-roll. Other than this, this file looks great!
Before:
After:
Comment #32
jenlamptonA few other notes:
$varsto$variablesbecause that should be handled by #1963942: Change all instances of $vars to $variables. So I rolled those back so the patch there wouldn't fail.Now after, with a few less lines:
Comment #33
star-szrThanks! These docs tweaks apply to both Twig templates in the patch:
Combine the first two sentences, the second is a fragment. "through CSS, including:"
Make each class a bullet in a list and remove the dots from the classes since we're talking about markup here. Also 'through' on the second line should not be indented by one space - see http://drupal.org/node/1354#lists, it should match the indent level.
Capitalize CSS here, capitalize 'View' (there are other spots where it makes sense to capitalize 'View' as well).
Comment #34
kgoel commentedI am going to work on this issue.
Comment #35
kgoel commentedAttached patch.
Comment #36
kgoel commentedFixed whitespace issue.
Comment #37
jenlamptonWow, great job, looking really close. I think you meant this to be a comma instead of a period:
how about "style contextually through CSS, including:"
Other than this one small change, this looks RTBC to me!
Comment #38
kgoel commentedFixed small grammer.
Comment #39
star-szrThanks @kgoel! The lists of classes need a bit of touch-up (check the indent and make sure there is a space after the bullet). See the example in http://drupal.org/node/1354#lists for reference. The template in views_test_data is closer to being correct.
Comment #40
kgoel commentedPatch attached.
Comment #41
star-szrThanks @kgoel! An interdiff is helpful to show the changes made between patches as well :)
core/modules/views/tests/views_test_data/templates/views-view--frontpage.html.twig:
This one is perfect.
core/modules/views/templates/views-view.html.twig:
The bullets on this one need to be indented by one more space, and the second line "through CSS" is indented by one space too many, it should line up with the previous line.
Comment #42
kgoel commentedThanks Cottser!
Comment #43
kgoel commentedChanged status
Comment #44
thedavidmeister commented+ * - view: The view object.views module.+ * - directory: The location of the views module."Views" is capital V
+ * Prepares variables for container templates.For views_ui_preprocess_views_view(), this is a module implementing hook_preprocess_views_view() so shouldn't the docs be "Implements hook_preprocess_views_view()."?
+ * Prepares variables for view templates.View templates -> capital V
+ {% if header is not empty %}There's a bunch of "is not empty" checks that seem superfluous, {% if foo %} should be enough.
+ * @ingroup views_templatesWe're not using this in views template docs anymore. We *are* using
@ingroup themeablethough so that needs to be added.Attributes being used in the template but not documented: attachment_after, attachment_before, title, title_prefix
Comment #45
kgoel commented@ thedavidmeister- thanks for the feedback. Updated patch based on comments in #44.
Comment #46
kgoel commentedUpdated status
Comment #47
dawehnerDo we really have to rename the variable. I don't like the new name, because it doesn't respect the fact that empty is an area like header/footer, so it also contains things others then just a simple text.
Comment #48
joelpittet@dawehner yes because it a name conflict with 'is empty'. Would you rather change them all to header_area/footer_area/empty_area?
Comment #49
tim.plunkettI don't see how $empty conflicts with "is empty". I think $empty_area is fine, no need to change footer/header.
One thing this patch does is change "view" to "View", which is not something we do anywhere in the Views module. I'd rather see it left as is.
I see @Cottser suggested this in #33, but AFAIK it's not something we plan on doing anywhere else, and having it different on the theme layer is weird.
Comment #50
dawehnerTechnically speaking it's also wrong. It's the ViewExecutable object, not the View storage object.
I agree that empty_area is a better name
Comment #51
star-szrI'm not sure where the 'capitalize View' thing first came up, personally I'd rather it be lowercase. Thoughts?
Also:
@param array $vars
Comment #52
star-szrIt's possible I suggested capitalizing View in the first place. Either way, my thought is that we don't capitalize node, taxonomy, or block, so why should a view be any different?
Comment #53
thedavidmeister commented#51 - We don't have to capitalize the "V" - although I do find it weird that the module "Views" always has a capital "V" but a "view" wouldn't.
We should pick something and write it somewhere to be referenced though, because there's quite a few patches that will need a re-roll if we swap to lowercase.
Comment #54
fabianx commented#45: twig-views-view-1843744-45.patch queued for re-testing.
Comment #56
star-szrTagging for reroll.
Comment #56.0
star-szrmm
Comment #57
chrisjlee commentedMerge conflict here:
Decided to keep both hunks. Not sure if that's correct or not.
Comment #58
star-szrviews_ui_cache_set was removed in #1919700: [Change notice[ Replace views_ui_cache_set with a method on the ViewUI object so should not be added back here. The
* Theme preprocess for views-view.tpl.php.line should be removed from the patch here as well.Comment #59
chrisjlee commentedChanges as requested in #58.
Comment #60
chrisjlee commentedComment #61
tim.plunkettThis still needs to have the case reverted. Throughout most of the file.
Comment #62
shanethehat commentedChanges capitalization of view/views as per IRC discussion.
Comment #63
tim.plunkettThese are still backwards, should be lowercase
might as well put string and string|null in here as well
@param \Drupal\views\ViewExecutable $view
This is still $vars
What is this directory? Why is it the location of the Views module?
Comment #64
thedavidmeister commentedComment #65
thedavidmeister commentedComment #66
joelpittetComment #67
joelpittetReverted empty_message back to empty because I tested it in twig proper and it seemed to work as a var, V to v and touchups from #65
Comment #68
thedavidmeister commentednitpicks:
unnecessary comma.
+ * - empty: The empty text to display if the view is has no rows."if the view is has no rows" - weird
+ * - more: A link to view more, if any.view more what? if this is the views "more" link we could do better here to explain what it is. The "full" explanation from the Views UI is:
I don't think we need all of that, but a bit more background info on what "more" means could be useful here - maybe explain that it's part of the pagination functionality and that it links to the page display for this view. What does "if any" mean here? how could I have "any view mores"?
Comment #69
thedavidmeister commented+ * - feed_icon: Feed icon to display, if any.the "if any" thing is awkward here too. "if any" really only makes sense if you're talking about a list of things that might be empty, not a singular thing that may or may not exist.
+ * @ingroup views_templates@ingroup themeable
+ {{ title_prefix }}+ {{ title }}+ {{ title_suffix }}+ {{ attachment_before }}+ {{ attachment_after }}undocumented variables in the Twig templates.
Comment #70
star-szrTagging for profiling.
Comment #71
joelpittetMy take on the doc cleanup from #68 and #69
Comment #72
thedavidmeister commentedThere's still a few undocumented variables in the Twig template as per #69.
Comment #73
shanethehat commentedComment #75
shanethehat commented#73: twig-views-view-1843744-73.patch queued for re-testing.
Comment #76
thedavidmeister commentedcode looks good. I'm going to re-tag for manual testing because we had a merge conflict and changed some functions around since #32
Comment #77
thedavidmeister commentedi'll test this.
Comment #78
thedavidmeister commentedHEAD:
#73:
Diff:
Comment #79
thedavidmeister commentedInterestingly... the view-dom-id-HASH changes on every page load with and without the template. That seems bad...
Comment #79.0
thedavidmeister commentedUpdated issue summary.
Comment #80
thedavidmeister commentedComment #81
mr.baileysProfiled with a views block containing one article on the front page:
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519afeb71bb40&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519afeb71bb40&...
Comment #82
dawehnerJust to be nitpicky ... should be @param \Drupal\views...
Comment #83
sean charles commentedProfiled with one views block listing one basic page on the front page.
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519b0b3c13638&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=519b0b3c13638&...
Comment #84
thedavidmeister commentedJust needs work on #82. Profiling looks good :)
Comment #86
mr.baileysRe-rolled for #82
Comment #87
star-szrSorry, needs more doc tweaks, profiling looks great though. Can someone please roll a new patch and interdiff with the following changes:
Per http://drupal.org/node/1354#lists when starting a sub-list we need to end the line before in a colon, e.g. "Remaining HTML attributes for the element, including:"
I think this whole section of the docblock in views-view--frontpage.html.twig should be replaced with the one in views-view.html.twig assuming the frontpage one doesn't have any more variables documented than the default views-view one.
We discussed in #1913208: [policy] Standardize template preprocess function documentation (starting around comment #37) that this should probably just be:
Implements hook_preprocess_HOOK() for views-view.html.twig.
We don't need to re-document the vars here. Just the one line should be good.
Comment #88
hydra commentedSo let's reroll this!
Comment #90
hydra commented#88: twig-views-view-1843744-88.patch queued for re-testing.
Comment #91
thedavidmeister commentedComment #92
star-szrThanks @Hydra, you rock!
This should be @ingroup themeable.
It also looks like we lost css_name and css_class docs, but they still look to be added in preprocess, can we add those back please (to both templates):
Comment #93
hydra commented... it's you rocking here, I'm just your patching slave! You find those tweaks like a machine, I'm admireing that!
Comment #94
joelpittetJust a couple more doc nitpicks.
Can you remove the $'s from the twig docblock?
Please add the @see template_preprocess() and @see template_preprocess_views_view() to the twig docblock.
Comment #95
hydra commentedOh gosh, I have defenetly go to bed, this is embrassing, sry for that -.-" Thx for the quick review :)
Comment #97
thedavidmeister commented#95: twig-views-view-1843744-95.patch queued for re-testing.
Comment #98
star-szrI think I missed this one before, again this should be @ingroup themeable.
Then ready :)
Thanks!
Comment #99
hydra commented:)
Comment #100
star-szrFound one more thing:
title_prefix is here twice (second should be called title_suffix) and both variables are missing a '-' bullet point.
Please fix in both .html.twig template files :)
Comment #101
hydra commentedNext round...
Comment #102
bradwade commentedprofiling it!
Comment #103
star-szrDoes not need further profiling, good profiling results in #83 and only changes since then have been documentation.
Thanks everyone!
Comment #104
alexpott+1. Ready for #1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch
Comment #105
star-szrJust adding back title_suffix var docs, part of the megapatch at #1987510: [meta] Convert all core *.tpl.php templates to Twig as singular patch.
Comment #106
alexpottNeeds a re-roll
Comment #107
socketwench commentedWorking on it!
Comment #108
socketwench commentedComment #109
tlattimore commentedI'll review 108.
Comment #110
tlattimore commentedI can confirm that the patch from #108 applies cleanly and works as described.
RTBC!
Comment #111
star-szrAnd also green now! Thanks a million @socketwench and @tlattimore (and everyone who worked on this issue) :)
Comment #112
alexpottCommitted 3cdae05 and pushed to 8.x. Thanks!
Comment #113.0
(not verified) commentedadded manual testing steps