You are here

function ajax_comments_preprocess_pager in AJAX Comments 8

Implements template_preprocess_pager().

File

./ajax_comments.module, line 298
AJAX comments module file.

Code

function ajax_comments_preprocess_pager(&$variables) {

  // Query parameters are added in
  // core/includes/pager.inc in the template_preprocess_pager(),
  // where pager_query_add_page() calls pager_get_query_parameters(),
  // which will pick up the ajax wrapper format from the ajax request, which breaks
  // the pager.
  // Unfortunately there is no way to remove this parameter before it is rendered to text,
  // so this preprocess function removes the parameter with string replacement.
  // Remove ajax wrapper format from first, previous.
  if (isset($variables['items']['first'])) {
    $variables['items']['first']['href'] = str_replace('_wrapper_format=drupal_ajax&', '', $variables['items']['first']['href']);
  }
  if (isset($variables['items']['previous'])) {
    $variables['items']['previous']['href'] = str_replace('_wrapper_format=drupal_ajax&', '', $variables['items']['previous']['href']);
  }

  // Remove ajax wrapper format from specific page links.
  if (isset($variables['items']['pages'])) {
    foreach ($variables['items']['pages'] as $key => $value) {
      $variables['items']['pages'][$key]['href'] = str_replace('_wrapper_format=drupal_ajax&', '', $value['href']);
    }
  }

  // Remove ajax wrapper format from next, last.
  if (isset($variables['items']['next'])) {
    $variables['items']['next']['href'] = str_replace('_wrapper_format=drupal_ajax&', '', $variables['items']['next']['href']);
  }
  if (isset($variables['items']['last'])) {
    $variables['items']['last']['href'] = str_replace('_wrapper_format=drupal_ajax&', '', $variables['items']['last']['href']);
  }
}