Problem/Motivation
I ran into this issue will fixing a "bug" on a current project. We have view page, using ajax and a mini-pager. We also have Views Ajax History module turned on. When paging the second time and beyond, you loose the correct url. While investigating this, it seems the mini pager copies a lot from the Full pager, which it should. And the plugin (Drupal\views\Plugin\views\pager\Mini) implements the theme with a variable "#route_name" but never uses it.
So here is a test I did to explain further. There is more to that total issue, but this is the first part for mini-pagers:
Full Pager w/ Views Ajax History:
- Load Page: http://dev-bcd83.pantheonsite.io/ajax-views-full-pager
- Click Page 2, get http://dev-bcd83.pantheonsite.io/ajax-views-full-pager?page=1
- Click Page 3, http://dev-bcd83.pantheonsite.io/ajax-views-full-pager?ajax_page_state[t...
Mini Pager w/ Views Ajax History:
- Load Page, http://dev-bcd83.pantheonsite.io/ajax-views-mini-pager
- Click Next, http://dev-bcd83.pantheonsite.io/ajax-views-mini-pager?page=1
- Click Next, http://dev-bcd83.pantheonsite.io/views/ajax?ajax_page_state[theme]=barti...
Proposed resolution
I believe the views_mini_pager theme needs to add "route_name" as a variable and the preprocess function needs to use the route just like the full pager.
Also, for those that need an immediate fix, this can be accomplished through alters and preprocesses...
function MODULE_theme_registry_alter(&$theme_registry) {
// Fix core bug with mini pager.
$theme_registry['views_mini_pager']['variables']['route_name'] = '';
}
// Overwrite preprocess functions.
function MODULE_preprocess_views_mini_pager(&$variables) {
global $pager_page_array, $pager_total;
$tags = &$variables['tags'];
$element = $variables['element'];
$parameters = $variables['parameters'];
$route_name = $variables['route_name'];
$route_parameters = [];
// Current is the page we are currently paged to.
$variables['items']['current'] = $pager_page_array[$element] + 1;
if ($pager_total[$element] > 1 && $pager_page_array[$element] > 0) {
$options = [
'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] - 1),
];
$variables['items']['previous']['href'] = \Drupal::url($route_name, $route_parameters, $options);
if (isset($tags[1])) {
$variables['items']['previous']['text'] = $tags[1];
}
$variables['items']['previous']['attributes'] = new Attribute();
}
if ($pager_page_array[$element] < ($pager_total[$element] - 1)) {
$options = [
'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1),
];
$variables['items']['next']['href'] = \Drupal::url($route_name, $route_parameters, $options);
if (isset($tags[3])) {
$variables['items']['next']['text'] = $tags[3];
}
$variables['items']['next']['attributes'] = new Attribute();
}
}
Remaining tasks
I've included a patch
Comment | File | Size | Author |
---|---|---|---|
mini-pager-theme.patch | 2.46 KB | pingevt | |
Comments
Comment #2
LendudeViews is in Drupal core now, moving to the right queue.
Seems related/duplicate of #2866386: Assert the view path is set correctly after second ajax request, have you tried the patch there?
Comment #3
mmjvb CreditAttribution: mmjvb as a volunteer commentedSuspect this to be for 8.8 or even 8.7. See no reason for this to be postponed to 9.x.
Waiting for answer on question in #2.
When answered should probably set to Needs review due to patch provided.
Comment #6
pameeela CreditAttribution: pameeela commentedThanks for reporting this issue. We rely on issue reports like this one to resolve bugs and improve Drupal core.
As part of the Bug Smash Initiative, we are triaging issues that are marked "Postponed (maintainer needs more info)".
Since there was no additional information provided since the issue was postponed or #2866386: Assert the view path is set correctly after second ajax request was suggested as duplicate, I'm marking the issue "Closed (duplicate)". If anyone can provide information on why this issue is different, please add complete steps to reproduce the issue (starting from "Install Drupal core"), document those steps in the issue summary and set the issue status back to "Active".
Thanks!