On node view pages, the comments are shown below the node text, and this is sometimes very far down on the page (if the node body tekst is long). The pager below the comments (when there are more comments than allowed on one page) links to the top of the page, so the user has to scroll down past the node body on every page.

Unfortunately, theme('pager') doesn't support an #fragment argument.

This patch changes the $parameters and $attributes for the theme_pager_XXX functions into an $options argument that is passed on to l() ($parameters is $options['query'] and $attributes is $options['attributes']), i.e. a more general solution. This also allows passing other options to l(), e.g. $options['html'] (e.g. if the pager links contain an <img> tag).

Additionally I made it possible to specify a different path than the current path, e.g. if the pager is inserted as a block on some other page that the main page. I don't know if this is a valid use case, but it way easy to do, so I guess the flexiblility may come out handy to someone.

CommentFileSizeAuthor
#6 pager-options-2.patch13.15 KBc960657
pager-options-1.patch13.09 KBc960657
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

I tested this and it works as described. I haven't had a chance to fully review the code yet, but at first glance it looks pretty good to me and I think is a valuable improvement to the site visitor experience.

Anonymous’s picture

Status: Needs review » Needs work

Actually, on the Find Content page, I get this notice:

Notice: Undefined index: parameters in theme_pager() (line 323 of /Users/clark/Documents/sites/drupal/includes/pager.inc).
Anonymous’s picture

Status: Needs work » Active

Sorry, it failed because I had done a git checkout and hadn't cleared the cache. This is why one shouldn't test patches after midnight ;)

Anonymous’s picture

Status: Active » Needs review

...or comment on issues after midnight. Changing back to needs review.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Tagging as novice for the task of rerolling the Drupal 8.x patch on account of #22336: Move all core Drupal files under a /core folder to improve usability and upgrades.

If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC.

c960657’s picture

Status: Needs work » Needs review
Issue tags: -Novice
FileSize
13.15 KB
thedavidmeister’s picture

Status: Needs review » Needs work

error: patch failed: core/includes/common.inc:6623
error: core/includes/common.inc: patch does not apply
error: patch failed: core/includes/pager.inc:351
error: core/includes/pager.inc: patch does not apply
error: patch failed: core/modules/comment/comment.module:732
error: core/modules/comment/comment.module: patch does not apply

trisketonni’s picture

Status: Needs work » Needs review

#6: pager-options-2.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, pager-options-2.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

almunnings’s picture

I got around the problem like so, if anyone gets into the same situation as me:

In a .module file.

/**
 * Implements template_preprocess_pager().
 */
function HOOK_preprocess_pager(&$variables) {
  if (empty($variables['pager']['#fragment'])) {
    return;
  }

  foreach ($variables['items'] as &$links) {
    if (!empty($links['href'])) {
      $links['href'] .= '#' . $variables['pager']['#fragment'];
    }
    foreach ($links as &$link) {
      if (!empty($link['href'])) {
        $link['href'] .= '#' . $variables['pager']['#fragment'];
      }
    }
  }
}

And when rendering the pager:

$render[] = [
  '#type' => 'pager',
  '#fragment' => 'DESIRED-FRAGMENT',
];

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ilechcod’s picture

Issue summary: View changes

Thanks AL Munings, just used #16 - was a lifesaver. Very clever!!!

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

maxilein’s picture

Version: 9.5.x-dev » 11.x-dev

This should definetely be on core. It prevents many very useful ui functionality. Eg staying on the same tab after page reload ...

maxilein’s picture

Title: Allow pager to link to #fragments (comment pager should link to comment section of page) » Allow pager to link to #fragments

I removed the: (comment pager should link to comment section of page) to make title more generic.

maxilein’s picture

Pagers don't seem to support url fragment attributes.

https://somesite/somepage?someparam=somevalue#somefragment

If creating a url using tokens the fragment attributes get lost somewhere on the way to page reload.

A pager which can keep fragments until the next reload would enable a lot of useful features (like jumping back to a comment, reopening the last selected tab, ...)

Maybe this can help.

code sample of a custom module:
https://www.drupal.org/project/drupal/issues/1293912#comment-13219514

module for links with fragments
https://www.drupal.org/project/menu_link_fragment

older patch for D7:
https://www.drupal.org/project/drupal/issues/1216628

maxilein’s picture

Title: Allow pager to link to #fragments » Allow pager to link to #fragment attributes