Problem/Motivation
$row_classes
should be on the context of the row which is being rendered.
Proposed resolution
Move $row_classes
to $row['attributes']
with the Attribute class.
This will need to move to move the $row
nested further to $row['content']
Remaining Tasks
- manual testing, with screenshots in #31
- needs code review
User interface changes
n/a
API changes
$row_classes
will no longer be available in views templates. Need to be converted to print $row['attributes']
, and in twig {{ row.attributes }}
and $row
will become $row['content']
or {{ row.attributes }}
Related Issues
#1843754: Convert views/templates/views-view-list.tpl.php to twig
#1843770: Convert views/templates/views-view-unformatted.tpl.php to twig
Comment | File | Size | Author |
---|---|---|---|
#68 | 1968398-68-views-row-classes-tests-only.patch | 963 bytes | joelpittet |
#68 | 1968398-68-views-row-classes.patch | 4.95 KB | joelpittet |
#65 | admin-people-before.png | 15.64 KB | echoz |
#65 | admin-people-after.png | 17.08 KB | echoz |
#63 | Screen Shot 2013-08-04 at 11.38.42 PM.png | 79.81 KB | markhalliwell |
Comments
Comment #1
joelpittetRough cut. Let me know if anything needs to change. Also converted Object references to Arrays for consistency and used all my powers to avoid doing any 'extra' cleanup.
Comment #2
dawehnerMh okay. At the moment I would prefer $row->foo over $row['foo'] but yeah if this will changed during twig, that's okay.
Comment #4
joelpittet@dawehner I agree, I prefer that too, it makes sense like in JS to have rows[{key:val},{key:val}], but it seems arrays are king, and PHP's version of object literals is not so cool( new stdClass()). So for now I was instructed to make things the same.
Here's a patch with that typo I missed in local testing.
Comment #6
joelpittetUndid some of my whitespace fixes and talked to some chx and merlinofchaos on IRC #drupal-vdc to confirm my "fix" for field content always being empty was indeed a mistake. So removed that. Also a random file snuck in there:S
Interdiff is against #1
Comment #7
dawehnerThis needs seriously manual testing :)
Comment #8
joelpittetComment #9
clemens.tolboomI cannot apply patch #6 to latest head.
Comment #10
joelpittetThanks @clemens.tolboom needed a re-roll cus it was older.
Comment #12
joelpittetfixing that rebase bit for views table.
Comment #13
intergalactic overlords CreditAttribution: intergalactic overlords commentedThe views table, html list and unformatted list are all fine.
There are some problems with the summaries and with the grid view though:
Comment #14
intergalactic overlords CreditAttribution: intergalactic overlords commentedsee #13
Comment #15
dawehnerAfaik we need <?php instead of <? here as it breaks on the testbot (if there is a test (see the glossary issue))
Just in general: If we change the actual content of these variables (for example attributes to them) these documentations should be adapted as well.
Comment #16
dawehnerAfaik we need <?php instead of <? here as it breaks on the testbot (if there is a test (see the glossary issue))
Just in general: If we change the actual content of these variables (for example attributes to them) these documentations should be adapted as well.
Comment #17
joelpittet#15 and #16 no longer exist as they are now twig templates. Thanks a lot guys for reviewing. I spotted my bugs in grid, thanks @intergalactic o...
Here's a re-roll, with fixes.
Comment #18
joelpittetComment #19
joelpittetTagging, needs re-roll due to other fixes regarding VDC renaming.
Comment #20
brunodboReroll.
Comment #22
brunodboWoops, bad reroll. New one incoming.
Comment #23
brunodboNew reroll.
Comment #24
brunodboGo testbot.
Comment #25
adamcowboy CreditAttribution: adamcowboy commentedNeed reroll
Comment #26
joelpittetRe-rolled
Comment #27
R.Hendel CreditAttribution: R.Hendel commentedYesterday I have tested #23. I created a view with for formats:
- grid
- html
- table
- unformatted
I compared the outcome before and after patching.
Everything looks fine to me besides html. I got following php-errors:
Will have to see if this happens also with latest patch...
Comment #28
markhalliwellMight be worth while to take a look at #1903746-44: Replace the views grid table template with one using divs.
I changed the Grid style to use the new Attribute system as well.
Comment #29
R.Hendel CreditAttribution: R.Hendel commentedI have tested latest patch #26 at simplytest.me.
There also happend that php error
User error: "0" is an invalid render array key in element_children() (line 5271 of core/includes/common.inc).
.But error messages were displayed at views backend this time. So this seems nothing to do for me with a special format. I'm not sure if this has something to do with that issue at all - but I'm not a dev... :-(
Comment #30
joelpittet#26: 1968398-26-views-row-classes.patch queued for re-testing.
Comment #31
R.Hendel CreditAttribution: R.Hendel commentedI have tested patch #26 at simplytest.me like I have done #27. I created a view with for formats:
- grid
- html
- table
- unformatted
This time everything worked fine and I got no error warnings, see screenshots:
grid:
html:
table:
unformatted:
Comment #32
dawehnerThe code looks great in general but I have some fear that these preprocess code gets more and more basically impossible to read/maintain. An array of 6 levels feels like madness.
Comment #33
YesCT CreditAttribution: YesCT commentedI updated the issue summary with a remaining tasks section.
The manual testing is awesome.
Still needs a code review before it can be rtbc.
Comment #34
joelpittet#26: 1968398-26-views-row-classes.patch queued for re-testing.
Comment #35
joelpittetThis will need a re-roll now that grid is all gussied up.
#1903746: Replace the views grid table template with one using divs
Comment #36
Les LimAlso needs to be re-rolled now that $vars is $variables everywhere. Working on it.
Comment #37
Les LimRe-rolled #26.
The grid-related changes committed in #1903746: Replace the views grid table template with one using divs have made the corresponding parts of this patch obsolete.
Comment #38
markhalliwellPatch looks good! Just one tiny nitpick that I'm aware of:
Don't need to instantiate a new Attribute class here, it's now lazy loaded in (see: #1982024: Lazy-load Attribute objects later in the rendering process only if needed). Change it so it's just an array.
After that, if patch is green and manual testing is done, this looks to be an RTBC issue!
Comment #39
Les LimNew patch reflecting #38.
Comment #40
markhalliwellReviewed revisions, patch is good. RTBC once manual testing is done and test comes back green.
Comment #41
dawehnerIt would feel better if someone could do another great manual testing like #31
Comment #42
Les LimTested a view with 4 displays, each with a custom row class set to "foo-[counter]". Hacked Bartik to add a yellow background style to "foo-2". Everything looks good.
The yellow background doesn't show in the grid display because of #2048897: Views Grid style: tokens not replaced in custom row/column classes, but that's a separate issue. The row classes are otherwise correct.
Comment #43
markhalliwellLooks good to me.
Comment #44
alexpottI think this @todo is unnecessary
Comment #45
markhalliwellOk, I updated the doc for this template (I think it just got overlooked). There were a few other things that needed to be changed too.
Comment #47
Les LimRe-rolled #45.
Comment #49
markhalliwellHere's the patch that actually fixes the two
$vars
that were added by #864006-81: Improve table semantics by adding scope or headers/id attributes and needed refactoring anyway.Comment #50
markhalliwellHere's the real interdiff from #47 -> #49.
Comment #52
markhalliwellErrors were because the row was continuing on empty rows. This caused the attributes array from being converted into a new Attribute object. Tests should pass now.
Comment #53
Fabianx CreditAttribution: Fabianx commentedLooks good!
Comment #54
dawehnerAgreed
Comment #55
bdone CreditAttribution: bdone commentedsimilar work was done in #2036369: Cleanup views.theme.inc
Comment #56
alexpottCommitted 0e6c03d and pushed to 8.x. Thanks!
Comment #57
echoz CreditAttribution: echoz commentedI believe this commit caused this visual regression to afaict just the people view. Reverting it locally returns the view to it's expected state. There are 2 hidden cells using space and pushing the dropbutton out. These are views-field-edit-node and views-field-translation-link. Possibly unrelated, in the people view, Translation link has broken/missing handler.
field edit node td
field translation link td
Comment #58
joelpittet@echoz re #57 From your screenshots I can't identify the visual regression you are speaking of and the firebug output in there has identical classes and markup. Can you show the before and after visual change and more helpfully the markup that has produced the visual change?
Thanks for looking into this!
Comment #59
echoz CreditAttribution: echoz commentedThe identified classes in dev tools are just highlighting in GREEN the 2 blank cells. This screenshot shows how the dropbutton is pushed 2 cells to the right, where it is supposed to be under the th "Operations". In the previous screenshots, my browser window was narrower so the dropbutton was squished and less noticble. Aren't other's getting this with the People view (admin/people)?
Comment #60
joelpittetI see what you're getting at, here's a markup comparison on that page. I'll see if I can't find where this is going wrong.
FYI, this comparison is done against HEAD with the patch #52 reversed, if anybody cares to try before HEAD moves;)
Comment #61
joelpittetThanks @echoz I think I found the issue. I forgot that we moved the attributes directly on the field being built instead of it's own variables. So what was happening is that the attributes that the hidden/excluded fields would have gotten if they weren't excluded was building the column unintentionally.
I moved the exclude check higher up which should do two things:
I also moved the long column key reference to a reference variable so that less mistakes are made reading that path and copying it, because I noticed another mistake like that in the code. See below:
missing 'columns'
Comment #62
joelpittetHa, thing I said I fixed I forgot... so here's that.
Comment #63
markhalliwellPatch in #62 is good. Tested the patch in simplytest.me:
Comment #64
joelpittetThis would be nice if it had a test to check that the container doesn't get rendered maybe if it's excluded. There is exclude tests in views already but it doesn't check the container... not totally sure if this test is needed but putting it out there...
Comment #65
echoz CreditAttribution: echoz commentedGood visually here too. I know not necessary, but I had a look, so did screenshots too.
Before patch #62
After patch #62
Comment #66
alexpottThis is testable so we should test it - therefore we can ensure we don't break this in the same way again.
Also the priority of this is critical because things are unusable the way they are.
Comment #67
joelpittetNot sure where the tests should go or if I should try to augment the FieldUnitTest.php where it already tests the exclude, so I'll start with that and if anybody has some hints please send.
I'm assigning this to myself, in the meantime.
Comment #68
joelpittetFirst patch should fail and second should pass. Let me know if the tests will fit the bill?
Comment #69
markhalliwellTest only patch failed as expected and new complete patch passed. Code looks good. Setting back to RTBC.
Comment #70
alexpottCommitted 4962369 pushed to 8.x. Thanks for the test @joelpittet! nice work
Comment #71.0
(not verified) CreditAttribution: commentedadded remaining tasks
Comment #72
joelpittetComment #73
AnybodyHi all and sorry to post into this issue but I guess it is definitely related and we should perhaps change or clarify things. Of course we can and should create a follow-up issue but I think it makes sense to link the problem here and have a short discussion perhaps...
The root of our "logical" problem can be seen in #27 already but doesn't seem to have been addressed finally in a straight way:
Have a look at the following comparison in views core module twig files:
views-view.html.twig:
Renders "{{ rows }}"
while
views-view-unformatted.html.twig
loops through rows.
So good and so clear...
What you might think now is that the longer variant from ...-unformatted.html.twig is just an optional bonus to add the row class wrappers and {{ rows }} as shorthand SHOULD also work in -unformatted.html.twig files, if you don't need it.
But NO, this leads to a watchdog full of
So my suggestion would be to ensure that {{ rows }} always works as expected or we find a different solution to tell themers that this is a completely different structure in certain cases and needs different handling... I guess we're not the only ones who ran into this problem...
Does this only happen in -unformatted.html.twig or also in other views-view.html.twig overrides?
Any ideas? Thank you very much for your help!
Comment #74
joelpittet@Anybody that's an interesting observation.
I'd suggest because we can't change the variable name for obvious reasons (breaks all sites everywhere) or change the way it works but the documentation doesn't really indicate that the
views-view.html.twig
'srows
is a render array, I'd suggest opening up a follow-up for improving documentation of rows inviews-view.html.twig
to indicate it's a render array holding the content