0

I have a view with two separate displays that is used in one single page. Both the displays are using a pager. To get things working I set a unique id for each pager under pager options. This works and I can use each pager independently. The problem is that the separator used in the url to distinguish between the two pagers is encoded as %2C. So my question is if there is a way to avoid this and if possible even change the character used?

  • Commas should be encoded (they're reserved chars per RFC3986)...is it causing you a problem? – Clive Feb 11 '15 at 16:11
  • @Clive - Oh, I though it was a + character. But like I stated in my OP is there a way to change the character used as separator? I think it would be much nicer with a + or - sign. Or perhaps same way to use two different placeholders like ?page1=1&page2=1 – Cyclonecode Feb 11 '15 at 16:12
0

I believe this is only possible by hacking the core pager functionality, so I wouldn't suggest it.

You could add this to your theme

function MYTHEME_pager_link($variables) {
  $text = $variables['text'];
  $page_new = $variables['page_new'];
  $element = $variables['element'];
  $parameters = $variables['parameters'];
  $attributes = $variables['attributes'];

  $page = isset($_GET['page']) ? $_GET['page'] : '';
  if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) {
    $parameters['page'] = $new_page;
  }

  $query = array();
  if (count($parameters)) {
    $query = drupal_get_query_parameters($parameters, array());
  }
  if ($query_pager = pager_get_query_parameters()) {
    $query = array_merge($query, $query_pager);
  }

  // Set each pager link title
  if (!isset($attributes['title'])) {
    static $titles = NULL;
    if (!isset($titles)) {
      $titles = array(
        t('« first') => t('Go to first page'),
        t('‹ previous') => t('Go to previous page'),
        t('next ›') => t('Go to next page'),
        t('last »') => t('Go to last page'),
      );
    }
    if (isset($titles[$text])) {
      $attributes['title'] = $titles[$text];
    }
    elseif (is_numeric($text)) {
      $attributes['title'] = t('Go to page @number', array('@number' => $text));
    }
  }

  // @todo l() cannot be used here, since it adds an 'active' class based on the
  //   path only (which is always the current path for pager links). Apparently,
  //   none of the pager links is active at any time - but it should still be
  //   possible to use l() here.
  // @see http://drupal.org/node/1410574
  $attributes['href'] = url($_GET['q'], array('query' => $query));
  return '<a' . drupal_attributes($attributes) . '>' . check_plain($text) . '</a>';
}

You'd need to change this line if ($new_page = implode(',', pager_load_array($page_new[$element], $element, explode(',', $page)))) { to use the separator you wanted.

But you'd also have to change a line in Drupal's core pager include (/includes/pager.inc)

In this function you'd change the character in the explode to what you want to use.

function pager_find_page($element = 0) {
  $page = isset($_GET['page']) ? $_GET['page'] : '';
  $page_array = explode(',', $page);
  if (!isset($page_array[$element])) {
    $page_array[$element] = 0;
  }
  return (int) $page_array[$element];
}

Edit: keep in mind, this will break pagers that are not using your theme which means your admin pagers probably won't work unless you do the same for your admin theme.

| improve this answer | |
  • Modifying the core files doesn't feel like an option. – Cyclonecode Feb 12 '15 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.