You are here

protected function PagerPathSubscriber::modifyUrl in Tome 8

Modifies a URL to replace pager query parameters with paths.

Parameters

string $url: A URL.

Return value

string The modified URL.

2 calls to PagerPathSubscriber::modifyUrl()
PagerPathSubscriber::modifyDestination in modules/tome_static/src/EventSubscriber/PagerPathSubscriber.php
Reacts to a modify destination event.
PagerPathSubscriber::modifyHtml in modules/tome_static/src/EventSubscriber/PagerPathSubscriber.php
Reacts to a modify HTML event.

File

modules/tome_static/src/EventSubscriber/PagerPathSubscriber.php, line 68

Class

PagerPathSubscriber
Converts pager query parameters to static paths.

Namespace

Drupal\tome_static\EventSubscriber

Code

protected function modifyUrl($url) {
  parse_str(parse_url($url, PHP_URL_QUERY), $query);
  if ($query && isset($query['page']) && is_numeric($query['page'])) {
    $base_path = preg_replace('/\\?.*/', '', $url);
    if ($query['page'] != 0) {
      if ($base_path === '/') {
        $base_path = '';
      }
      $url = $base_path . '/page/' . ($query['page'] + 1);
    }
    else {
      $url = !empty($base_path) ? $base_path : '/';
    }
  }
  return $url;
}