Spin-off from #1190436: Full Pager: The ellipsis ("...") button does nothing

This patch replaces all the theme_pager_* functions with theme suggestions based off of theme_pager_link(). With this change a themer can add any of the following functions to template.php:

mytheme_pager_link($variables){ ... }
mytheme_pager_link__first($variables){ ... }
mytheme_pager_link__last($variables){ ... }
mytheme_pager_link__previous($variables){ ... }
mytheme_pager_link__next($variables){ ... }
.. or they can create the corresponding tpl instead.

Patch by @bleen18

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bleen’s picture

Assigned: Unassigned » bleen

This is my summary copied from the original issue:

I replaced all the theme_pager_* functions with theme suggestions based off of theme_pager_link(). With this change a themer can add any of the following functions to template.php:

mytheme_pager_link($variables){ ... }
mytheme_pager_link__first($variables){ ... }
mytheme_pager_link__last($variables){ ... }
mytheme_pager_link__previous($variables){ ... }
mytheme_pager_link__next($variables){ ... }
.. or they can create the corresponding tpl instead.

Thanks @sun for copying this over ...

bleen’s picture

Issue tags: -theme system cleanup

drupal8.pager-theme.0.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +theme system cleanup

The last submitted patch, drupal8.pager-theme.0.patch, failed testing.

bleen’s picture

Status: Needs work » Needs review
FileSize
10.07 KB

reroll

Status: Needs review » Needs work

The last submitted patch, 1598886.patch, failed testing.

bleen’s picture

FileSize
10.06 KB

Doh! .. re-roll

bleen’s picture

Status: Needs work » Needs review
sun’s picture

Status: Needs review » Needs work
Issue tags: +API clean-up
+++ b/core/includes/pager.inc
@@ -266,149 +310,6 @@ function theme_pager($variables) {
-    $output = theme('pager_link', array('text' => $text, 'page_new' => pager_load_array(0, $element, $pager_page_array), 'element' => $element, 'parameters' => $parameters, 'attributes' => array('rel' => 'first')));
...
-      $output = theme('pager_link', array('text' => $text, 'page_new' => $page_new, 'element' => $element, 'parameters' => $parameters, 'attributes' => array('rel' => 'prev')));
...
-      $output = theme('pager_link', array('text' => $text, 'page_new' => $page_new, 'element' => $element, 'parameters' => $parameters, 'attributes' => array('rel' => 'next')));
...
-    $output = theme('pager_link', array('text' => $text, 'page_new' => pager_load_array($pager_total[$element] - 1, $element, $pager_page_array), 'element' => $element, 'parameters' => $parameters, 'attributes' => array('rel' => 'last')));

Apparently, this patch needed a re-roll due to the recently added 'rel' attributes.

They do not seem to be contained in the new code.

bleen’s picture

Status: Needs work » Needs review
FileSize
10.26 KB

I missed that, thanks ...

this patch includes the "rel" attributes

sun’s picture

Status: Needs review » Needs work
+++ b/core/includes/pager.inc
@@ -191,10 +191,44 @@ function theme_pager($variables) {
+    $li_previous = theme('pager_link__previous', array(
...
+      'attributes' => array('rel' => 'last'),

Previous has a rel of last.

+++ b/core/includes/pager.inc
@@ -191,10 +191,44 @@ function theme_pager($variables) {
+  // Create the "last" and "next" links if we are not on the last page.
+  if ($pager_page_array[$element] < ($pager_total[$element] - 1)) {
+    $li_last = theme('pager_link__last', array(
...
+    $li_next = theme('pager_link__next', array(

The special last and next links do not get rel attributes.

bleen’s picture

Status: Needs work » Needs review
FileSize
10.25 KB

I had a small error in #9. Please ignore it and review this one

Sun: WOW you're fast...

jenlampton’s picture

Status: Needs review » Needs work
jenlampton’s picture

Status: Needs work » Active

No, that was my code that needed to be updaed :/

jenlampton’s picture

Status: Active » Needs work

Okay, patch applies cleanly.

bartik_pager_link() works.
bartik_pager_link__first() works.
bartik_pager_link__last() works.

But bartik_pager_link__previous() and bartik_pager_link__next() seem to affect more than just the previous and next links. It also affects the numeric link that represents the same page as the next/prev link.

I don't think that's the desired affect.

bleen’s picture

Status: Needs work » Needs review
FileSize
10.23 KB

This should solve the issue that jenlampton caught in #14

bleen’s picture

FileSize
10.23 KB

... and one more without the whitespace issues

sun’s picture

Would be good to do another round of testing here, but otherwise this patch looks great to me :)

Do we want to make the merger of theme_pager_link* theme functions into theme_link() a separate follow-up issue? I think that attacking that separately would make sense, as it rather relates to the Theme Component Library idea/effort.

Thus, created two related follow-ups:
#1778990: Merge theme_pager_link*() theme functions into theme_link()
#1778992: Merge theme_menu_link/_local_task/_local_action() theme functions into theme_link()

podarok’s picture

catch’s picture

What tests do we need for this? Manual ones to ensure the CSS/Markup is equivalent? Would be good to get this one in.

bleen’s picture

Manual ones to ensure the CSS/Markup is equivalent

That is how I have been testing...

sun’s picture

Issue tags: +Needs manual testing

yeah, I meant manual tests in #17 and still think that's sufficient. Just to make sure that we don't have a mistake as in #14. ;)

dodorama’s picture

#16: 1598886.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Needs manual testing, +API clean-up, +theme system cleanup

The last submitted patch, 1598886.patch, failed testing.

dodorama’s picture

Status: Needs work » Needs review
FileSize
9.21 KB

This is my first attempt at re-rolling a patch. I hope it worked properly.

dodorama’s picture

I did a manual testing. Here's a diff of the markup.

--- /Users/dodo/Desktop/pager.html 
+++ (clipboard) 
@@ -4,17 +4,17 @@
       <a rel="first" title="Go to first page" href="/drupal/node">« first</a>
     </li>
     <li class="pager-previous even">
-      <a rel="first" title="Go to previous page" href="/drupal/node">‹ previous</a>
+      <a rel="prev" title="Go to previous page" href="/drupal/node">‹ previous</a>
     </li>
     <li class="pager-item odd">
-      <a rel="first" title="Go to page 1" href="/drupal/node">1</a>
+      <a title="Go to page 1" href="/drupal/node">1</a>
     </li>
     <li class="pager-current even">2</li>
     <li class="pager-item odd">
-      <a rel="last" title="Go to page 3" href="/drupal/node?page=2">3</a>
+      <a title="Go to page 3" href="/drupal/node?page=2">3</a>
     </li>
     <li class="pager-next even">
-      <a rel="last" title="Go to next page" href="/drupal/node?page=2">next ›</a>
+      <a rel="next" title="Go to next page" href="/drupal/node?page=2">next ›</a>
     </li>
     <li class="pager-last odd last">
       <a rel="last" title="Go to last page" href="/drupal/node?page=2">last »</a>

It looks good to me.

jwilson3’s picture

 <li class="pager-current even">2</li>

Its always bugged me that the links in the pager have the benefit of an extra element in the dom for theming, while the plain text items (current page, and ellipses) do not. This means you have to get creative (and inconsistent) with the CSS. Maybe this belongs as a separate request, for CSS lint cleanup or standardizing the Component Library but it would be incredibly useful to add a wrapper span around non-links in the pager, which would pave the way for consistent css like this:

.pager-last a,
.pager-first a,
.pager-next a,
.pager-previous a,
.pager-ellipse span,
.pager-current span {
  display: inline-block;
  ...
}

I understand if this is too little too late, but its worth a try ;)

jwilson3’s picture

In other words, #26 is justification for providing theme_pager_link__ellipse and theme_pager_link__current as well.

jwilson3’s picture

One more thing...

Quoting from the proposed resolution in #1499460: [meta] New theme system (emphasis added by me):

[...] we would like to write as few new templates as possible. Match theme functons to HTML and reuse them. For example, a list of menu links, a list of pager elements etc is just a list.

Please, correct me if wrong, but this kind of throws a monkey wrench into the current work to *create more themables for pagers*.

Without knowing too much about the internals of pagers, it seems like it would be pretty easy to convert pagers to a simple theme_list() if we moved the classes off of the LI into to the item appearing in the list, and used wrapper elements like SPANS suggested in #26. It would also make the CSS even *more* clean than the example in #26, because we could get away with using *just classes*:

<li class="odd first"><a rel="first" class="pager-first">« first</a></li>
<li class="even"><a rel="previous" class="pager-previous" [...]>[...]</a></li>
<li class="odd"><span class="pager-ellipse">...</span></li>
<li class="even"><a rel="current" class="pager-current active">...</a></li>
[etcetera]
.pager-last,
.pager-first,
.pager-next,
.pager-previous,
.pager-ellipse,
.pager-current {
  display: inline-block;
  ...
}
catch’s picture

@jwilson3: that's #1778990: Merge theme_pager_link*() theme functions into theme_link() but this patch makes that one easier - since we end up with only one pager theme function instead of four or however many it currently is to convert.

bleen’s picture

So based on the re-roll in #24 and the HTML diff in #25 is this now RTBC?

jwilson3’s picture

Thanks catch.

One more question, why are there two underscores in pager_link__first? is this a new feature of drupal 8 theming?

bleen’s picture

@jwilson .... actually that was added in D7. See http://drupal.org/node/1089656 for more details

jwilson3’s picture

#lightbulb. Ok, yeah. Definitely knew about theme suggestions, but always encountered that feature from the front end point of view '--', never really thought about how that could be useful in Drupal core. Nice usage here.

catch’s picture

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

RTBC per the manual testing.

podarok’s picture

Issue tags: +Twig

looks like its Twig related too
+1 RTBC for #24

sun’s picture

#24: cleanup-pager.patch queued for re-testing.

catch’s picture

Title: Clean up pager theme functions » Change notice: Clean up pager theme functions
Priority: Normal » Critical
Status: Reviewed & tested by the community » Active

Committed/pushed to 8.x, thanks!

Will need a change notice for the removed/replaced theme functions.

bleen’s picture

Havent done a change notice before so lemme know what Im missing... http://drupal.org/node/1819308

bleen’s picture

Status: Active » Needs review
catch’s picture

The content looks fine, but all the metadata/title etc. is about the entity render controller.

tim.plunkett’s picture

Status: Needs review » Needs work

It appears that instead of making a new change notice, you edited an existing one? I've reverted it. See http://drupal.org/node/1819308/revisions/view/2409260/2409470

I'm guessing you were using one as an example, and just copy/pasted into the wrong tab.

bleen’s picture

Status: Needs work » Needs review

DOH!!!!! Tim.plunkett nailed it.

Sorry bout that. This should be better: http://drupal.org/node/1819788

catch’s picture

Priority: Critical » Normal
Status: Needs review » Fixed

Looks great.

Tor Arne Thune’s picture

Title: Change notice: Clean up pager theme functions » Clean up pager theme functions

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Adding summary from original issue