Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Meta issue: #1843738: [meta] Convert views module to Twig
Comment | File | Size | Author |
---|---|---|---|
#66 | 1912604-66.patch | 2.79 KB | star-szr |
#59 | 1912604-59-twig-views-mini-pager.patch | 2.82 KB | mondrake |
#59 | interdiff_53-59.txt | 404 bytes | mondrake |
#53 | 1912604-53-twig-views-mini-pager.patch | 2.87 KB | mondrake |
#53 | interdiff_49-53.txt | 1.35 KB | mondrake |
Comments
Comment #1
gollyg CreditAttribution: gollyg commentedI have added the logic in the views-mini-pager to the preprocess function. However, this theme function ultimately outputs an item list (in fact it uses theme_item_list for its return value).
Which raises the questions:
I have attached the patch and marked for review to get some answers to those questions before proceeding.
Comment #2
gollyg CreditAttribution: gollyg commentedOkay, Fabianx helped me out here in IRC. Still don't know if this is the correct approach, but I have called the item-list theme function within the preprocess function, and then sent that output to the twig file to be rendered as is, or overridden.
On the include function, Fabianx said:
Comment #3
dawehnerMh, this would make it actually worse to theme, mhh.
Comment #4
gollyg CreditAttribution: gollyg commentedA little more detail? Does it require more variables passed to the function? Or what would be the best approach?
Comment #5
bzitzow CreditAttribution: bzitzow commentedI was instructed that the variable passed by reference should be changed for consistency to:
Comment #6
joelpittetComment #8
damiankloip CreditAttribution: damiankloip commentedThe last patch didn;t remove the previous theme function, as well as the item list render array being incorrect.
See how this gets on.
Comment #9
damiankloip CreditAttribution: damiankloip commentedSorry, also the last patch changed the output of the pager too, if we are converting, I don't think we should change too much what the mini pager is doing. Interdiff from last patch.
Comment #10
joelpittetNice job @damiankloip getting that to pass on this one. I have a few questions and nitpiky little things.
Should be keeping the period at the end.
We could probably replace $vars with $variables for consistency here, no? I've been doing that on these functions. @bzitzow mentioned this above as well.
Why are we removing the title attributes here?
Comment #11
damiankloip CreditAttribution: damiankloip commentedAsk the last patch author, The patch I fixed was from that :) Looks like they should probably stay though.
Comment #12
damiankloip CreditAttribution: damiankloip commentedHere's an updated patch, thought I might as well quickly reroll it.
Thanks for the review.
Comment #14
damiankloip CreditAttribution: damiankloip commentedValid php is usually good...
Comment #15
dawehnerThis doesn't display anything, it just implements preprocess.
Comment #16
star-szrTagging.
Comment #17
thedavidmeister CreditAttribution: thedavidmeister commentedShould be "Prepares variables for a Views mini-pager."
+ * - items: An array of pager elements.
We're not talking about PHP data types in Twig templates.
Comment #18
thedavidmeister CreditAttribution: thedavidmeister commentedFor the preprocess you also need:
Default template: views-mini-pager.html.twig.
and an @param for the variables.
Comment #19
star-szrThanks @thedavidmeister! Tagging the tweaks in #17 and #18 as a novice task, with only one correction for the first item mentioned in #17:
Per #1913208: [policy] Standardize template preprocess function documentation preprocess function names should end in 'templates', so maybe 'Prepares variables for Views mini-pager templates.'.
Comment #20
ronnienorwood CreditAttribution: ronnienorwood commentedComment #21
ronnienorwood CreditAttribution: ronnienorwood commentedComment #22
joelpittet@ronnienorwood just jumping on this to get it done. You are welcome to do more doc cleanup or manual testing to help get this in. Or if you would like another like this, I'm sure I could find one for you, just jump on IRC #drupal-twig and ping me.
Comment #23
joelpittethmm, I really got to watch out for that save button...
Comment #24
joelpittetComment #25
karangarske CreditAttribution: karangarske commentedGoal was to manually test that the mini pager is using twig template
How I tested
Verified the mini pager patch using twig was being used by adding a test string in the twig file
Tested as part of Florida Drupal Camp 2013
Comment #26
dawehnerTo just print the pager seems to be not really useful for theming. I'm wondering whether #1898474: pager.inc - Convert theme_ functions to Twig would improve the situation? In general it seems to be useful to generalize as much as possible from the normal pager.
Comment #27
star-szr@dawehner - the goal for now is to convert everything, and then consolidate later when it makes sense. Converting and consolidating simultaneously would be too much. See #1804614: [meta] Consolidate theme functions and properly use theme suggestions in core.
Comment #28
clemens.tolboomThe minipage is not displayed at all.
- I added 3 nodes
- On admin/structure/views/view/frontpage/edit
- Set pager side to 1
- Full pager is visible
- Mini pages is not. There is no code in the html according to
where /tmp/a (patch applied) and /tmp/b clean 8.x
Comment #29
Hydra CreditAttribution: Hydra commentedUnlike clemens.tolboom manual test, for me #23 worked. I did the same as karang did. Template is used properly
Comment #30
thedavidmeister CreditAttribution: thedavidmeister commented#28 - did you clear the cache after applying the patch? this is required to make the new template appear.
Comment #31
thedavidmeister CreditAttribution: thedavidmeister commentedComment #32
clemens.tolboom@thedavidmeister: tnx ... it was a cache clear :-/ ... sorry
I did not manage to move forward get past page 2: http://drupal.d8/node?page=1
And from http://drupal.d8/node?page=3 cannot move previous (http://drupal.d8/node?page=2) moves immediately to first page. Has this to do with #1625248: Mini Pager ("tags") are broken?
I have a pager size of 1 and 4 nodes so I expected good rendering on:
- http://drupal.d8/node
- http://drupal.d8/node?page=0
- http://drupal.d8/node?page=1 : No previous link
- http://drupal.d8/node?page=2 : No previous link
- http://drupal.d8/node?page=3
Comment #33
clemens.tolboomReported #1998330: Minipager is broken on page size == 1 due to ceil(PHP_MAX_INT / 1) mentioned in #32
Comment #34
Hydra CreditAttribution: Hydra commented@clemens.tolboom I belief this is related to #1898474: pager.inc - Convert theme_ functions to Twig, like dawehner mentioned in #26. I remember that the first time I tested the patch, I had the same behavior you described. Then I applyed the patch from #1898474: pager.inc - Convert theme_ functions to Twig and the pager worked for me, maybe you'll give this a try.
Comment #35
clemens.tolboomThe code I refer to in #1998330: Minipager is broken on page size == 1 due to ceil(PHP_MAX_INT / 1) comes from #1901290: Replace the mini pager with a lite pager (which does not run a count query) which is rather new Feb 18, 2013.
Comment #36
andyceo CreditAttribution: andyceo commented#23: 1912604-22-twig-views-mini-pager.patch queued for re-testing.
Comment #38
joelpittetNumber #23 doesn't apply any longer.
Here's a re-roll and some doc cleanup.
Comment #40
joelpittet#38: 1912604-12-twig-views-mini-pager.patch queued for re-testing.
Comment #41
mondrake#38 needed a re-roll after #1898474: pager.inc - Convert theme_ functions to Twig. Attached.
However, what's the purpose to have a Twig template like that here? Can't we just re-use pager.html.twig, and pass $variables['items'] instead of $variables['pager']?
Comment #43
mondrake#41: 1912604-41-twig-views-mini-pager.patch queued for re-testing.
Comment #44
mondrakeNeeds reroll after #1963942: Change all instances of $vars to $variables got committed.
Comment #45
joelpittetre-rolled from #41
Comment #46
mondrakeWe no longer need this
Comment #47
joelpittetThanks @mondrake.
Comment #48
mondrake#47: 1912604-48-twig-views-mini-pager.patch queued for re-testing.
Comment #50
mondrakeNeeded re-roll, see comment #15 in #2049723: Mini pager shows "Page 1" if there is non item at all available.
Comment #52
mondrakeComment #53
mondrake#50 failed because now we need to take into account, in the Twig template, that the preprocess may no longer return the pager items. Patch attached - to align with the main pager I also:
Comment #54
mondrakeComment #55
dawehnerWhile testing this patch I spotted #2055993: Ajax for mini pagers in the preview does not work but it also happens on HEAD, so this is fine.
This patch itself is totally fine.
Comment #56
mondrake#55 - this is broader than the mini pager, in fact occurs any time any 'navigational' link/button is clicked (any link/button that requires an update to the preview itself). See #2048309: Views UI Preview - navigation is broken, there is a patch there that longs for review :)
Comment #57
alexpottWhy are we adding this in this issue with no discussion of accessibility? This should be debated in another issue and this issue should be the straight conversion to Twig.
Also no profiling has been done.
Comment #58
star-szrAgreed - we should not be changing markup in this conversion. We can look at consolidating with the main pager template afterwards.
Comment #59
mondrakeAh sorry, just thought that copying/pasting from the main pager template would be ok.
Comment #60
mondrake... also created follow up #2058279: Align mini pager accessibility markup to full pager..
Comment #61
dawehnerNice!
Comment #62
star-szrNeeds profiling still, I can work on it.
Comment #63
star-szrProfiling looks great and I also did a markup comparison and it matches up perfectly.
Profiling results
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5204417bc7ab7&...
http://www.lionsad.de/xhprof-kit/xhprof/xhprof_html/?run1=5204417bc7ab7&...
Markup comparison
Before:
After:
Comment #64
star-szrI should add, the scenario was the default homepage view set to use the mini pager. I added 50 nodes via devel generate to get the pager to show up.
Comment #65
webchickThis looks good, but unfortunately no longer applies.
Comment #66
star-szrHad a branch from the profiling so here is a quick reroll.
Comment #67
mondrakeReroll was needed because of #2062315: Remove unnecessary 'pattern' lines in views_theme(). Back to RTBC.
Comment #68
alexpottCommitted 88b192c and pushed to 8.x. Thanks!
Comment #69.0
(not verified) CreditAttribution: commentedUpdated issue summary.