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

CommentFileSizeAuthor
mini-pager-theme.patch2.46 KBpingevt
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pingevt created an issue. See original summary.

Lendude’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 9.x-dev
Component: Code » views.module
Category: Task » Bug report
Issue tags: -ajax pager, -pager, -mini pager
Related issues: +#2866386: Assert the view path is set correctly after second ajax request

Views 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?

mmjvb’s picture

Version: 9.x-dev » 8.8.x-dev
Status: Active » Postponed (maintainer needs more info)

Suspect 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.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

pameeela’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)
Issue tags: +Bug Smash Initiative

Thanks 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!