diff --git a/core/includes/pager.inc b/core/includes/pager.inc index a33cb3c..ce68f2a 100644 --- a/core/includes/pager.inc +++ b/core/includes/pager.inc @@ -166,6 +166,21 @@ function template_preprocess_pager(&$variables) { $quantity = $variables['quantity']; global $pager_page_array, $pager_total; + // Nothing to do if there is only one page. + if ($pager_total[$element] <= 1) { + return; + } + + // Fill in default link labels. + $tags = &$variables['tags']; + $tags += array( + t('« first'), + t('‹ previous'), + '', + t('next ›'), + t('last »'), + ); + // Calculate various markers within this pager piece: // Middle is used to "center" pages around the current page. $pager_middle = ceil($quantity / 2); @@ -197,44 +212,65 @@ function template_preprocess_pager(&$variables) { $li_previous = ''; $li_next = ''; $li_last = ''; + $current_path = current_path(); // Create the "first" and "previous" links if we are not on the first page. if ($pager_page_array[$element] > 0) { $li_first = array( - '#theme' => 'pager_link__first', - '#text' => (isset($tags[0]) ? $tags[0] : t('« first')), - '#page_new' => pager_load_array(0, $element, $pager_page_array), + '#theme' => 'link__pager__first', + '#text' => $tags[0], + '#path' => $current_path, '#element' => $element, - '#parameters' => $parameters, - '#attributes' => array('rel' => 'first'), + '#options' => array( + 'query' => pager_query_add_page($parameters, $element, 0), + 'attributes' => array( + 'title' => t('Go to first page'), + 'rel' => 'first', + ), + ), ); $li_previous = array( - '#theme' => 'pager_link__previous', - '#text' => isset($tags[1]) ? $tags[1] : t('‹ previous'), - '#page_new' => pager_load_array($pager_page_array[$element] - 1, $element, $pager_page_array), + '#theme' => 'link__pager__previous', + '#text' => $tags[1], + '#path' => $current_path, '#element' => $element, - '#parameters' => $parameters, - '#attributes' => array('rel' => 'prev'), + '#options' => array( + 'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] - 1), + 'attributes' => array( + 'title' => t('Go to previous page'), + 'rel' => 'prev', + ), + ), ); } // Create the "last" and "next" links if we are not on the last page. if ($pager_page_array[$element] < ($pager_total[$element] - 1)) { $li_next = array( - '#theme' => 'pager_link__next', - '#text' => isset($tags[3]) ? $tags[3] : t('next ›'), - '#page_new' => pager_load_array($pager_page_array[$element] + 1, $element, $pager_page_array), + '#theme' => 'link__pager__next', + '#text' => $tags[3], + '#path' => $current_path, '#element' => $element, - '#parameters' => $parameters, - '#attributes' => array('rel' => 'next'), + '#options' => array( + 'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1), + 'attributes' => array( + 'title' => t('Go to next page'), + 'rel' => 'next', + ), + ), ); $li_last = array( - '#theme' => 'pager_link__last', - '#text' => (isset($tags[4]) ? $tags[4] : t('last »')), - '#page_new' => pager_load_array($pager_total[$element] - 1, $element, $pager_page_array), + '#theme' => 'link__pager__last', + '#text' => $tags[4], + '#path' => $current_path, '#element' => $element, - '#parameters' => $parameters, - '#attributes' => array('rel' => 'last'), + '#options' => array( + 'query' => pager_query_add_page($parameters, $element, $pager_total[$element] - 1), + 'attributes' => array( + 'title' => t('Go to last page'), + 'rel' => 'last', + ), + ), ); } @@ -266,12 +302,19 @@ function template_preprocess_pager(&$variables) { $items[] = array( '#wrapper_attributes' => array('class' => array('pager-item')), 'link' => array( - '#theme' => 'pager_link', + '#theme' => 'link__pager', '#text' => $i, - '#page_new' => pager_load_array($i - 1, $element, $pager_page_array), + '#path' => $current_path, + '#options' => array( + 'query' => pager_query_add_page($parameters, $element, $i - 1), + 'attributes' => array( + 'title' => t('Go to page @number', array('@number' => $i)), + ), + ), '#element' => $element, + // Specify how many pages are between this item and the current page. + // Ignored by default, supplied for alternative implementations. '#interval' => ($pager_current - $i), - '#parameters' => $parameters, ), ); } @@ -285,16 +328,24 @@ function template_preprocess_pager(&$variables) { $items[] = array( '#wrapper_attributes' => array('class' => array('pager-item')), 'link' => array( - '#theme' => 'pager_link', + '#theme' => 'link__pager', '#text' => $i, - '#page_new' => pager_load_array($i - 1, $element, $pager_page_array), + '#path' => $current_path, + '#options' => array( + 'query' => pager_query_add_page($parameters, $element, $i - 1), + 'attributes' => array( + 'title' => t('Go to page @number', array('@number' => $i)), + ), + ), '#element' => $element, + // Specify how many pages are between this item and the current page. + // Ignored by default, supplied for alternative implementations. '#interval' => ($i - $pager_current), - '#parameters' => $parameters, ), ); } } + // Check whether there are further next pages. if ($i < $pager_max) { $items[] = array( '#wrapper_attributes' => array('class' => array('pager-ellipsis')), @@ -325,67 +376,36 @@ function template_preprocess_pager(&$variables) { } /** - * Prepares variables for pager link templates. + * Adds the 'page' parameter to the query parameter array of a pager link. * - * Default template: pager-link.html.twig. + * @param array $query + * An associative array of query parameters to add to. + * @param integer $element + * An integer to distinguish between multiple pagers on one page. + * @param integer $index + * The index of the target page in the pager array. * - * @param array $variables - * An associative array containing: - * - text: The link text. Also used to figure out the title attribute of the - * link, if it is not provided in $variables['attributes']['title']; in - * this case, $variables['text'] must be one of the standard pager link - * text strings that would be generated by the pager theme functions, such - * as a number or t('« first'). - * - page_new: The first result to display on the linked page. - * - element: An optional integer to distinguish between multiple pagers on - * one page. - * - parameters: An associative array of query string parameters to append to - * the pager link. - * - attributes: An associative array of HTML attributes to apply to the - * pager link. + * @return array + * The altered $query parameter array. * - * @see template_preprocess_pager() + * @todo Document the pager/element/index architecture and logic. It is not + * clear what is happening in this function as well as pager_load_array(), + * and whether this can be simplified in any way. */ -function template_preprocess_pager_link(&$variables) { - $text = $variables['text']; - $page_new = $variables['page_new']; - $element = $variables['element']; - $parameters = $variables['parameters']; - $attributes = $variables['attributes']; +function pager_query_add_page(array $query, $element, $index) { + global $pager_page_array; + + // Determine the first result to display on the linked page. + $page_new = pager_load_array($index, $element, $pager_page_array); $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()); + $query['page'] = $new_page; } 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)); - } - } - - $variables['link'] = l($text, current_path(), array('query' => $query, 'attributes' => $attributes)); + return $query; } /** diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 09c3460..15bb7df 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -3213,10 +3213,6 @@ function drupal_common_theme() { 'variables' => array('tags' => array(), 'element' => 0, 'parameters' => array(), 'quantity' => 9), 'template' => 'pager', ), - 'pager_link' => array( - 'variables' => array('text' => NULL, 'page_new' => NULL, 'element' => NULL, 'parameters' => array(), 'attributes' => array()), - 'template' => 'pager-link', - ), // From menu.inc. 'menu_link' => array( 'render element' => 'element', diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index aed41f6..66ebdf2 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -96,10 +96,7 @@ function template_preprocess_search_results(&$variables) { '#module' => $variables['module'], ); } - $variables['pager'] = array( - '#theme' => 'pager', - '#tags' => NULL, - ); + $variables['pager'] = array('#theme' => 'pager'); // @todo Revisit where this help text is added, see also // http://drupal.org/node/1918856. $variables['help'] = search_help('search#noresults', drupal_help_arg()); diff --git a/core/modules/system/templates/pager-link.html.twig b/core/modules/system/templates/pager-link.html.twig deleted file mode 100644 index 10fdb04..0000000 --- a/core/modules/system/templates/pager-link.html.twig +++ /dev/null @@ -1,16 +0,0 @@ -{# -/** - * @file - * Default theme implementation to display a pager link. - * - * Available variables: - * - link: The pager link. - * - * @see template_preprocess() - * @see template_preprocess_pager_link() - * - * @ingroup themeable - */ - @todo Revisit this template after http://drupal.org/node/1595614 is resolved. -#} -{{ link }} diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index 7c04815..5149547 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -255,7 +255,7 @@ function user_admin_account() { '#options' => $options, '#empty' => t('No people available.'), ); - $form['pager'] = array('#markup' => theme('pager')); + $form['pager'] = array('#theme' => 'pager'); return $form; } diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 12cc7cf..e2ab8dd 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -1144,31 +1144,37 @@ function theme_views_mini_pager($vars) { // Current is the page we are currently paged to. $pager_current = $pager_page_array[$element] + 1; - // End of marker calculations. + $current_path = current_path(); $li_previous = array(); if ($pager_total[$element] > 1 && $pager_page_array[$element] > 0) { $li_previous = array( - '#theme' => 'pager_link__previous', + '#theme' => 'link__pager__previous', '#text' => (isset($tags[1]) ? $tags[1] : t('‹‹')), - '#attributes' => array('title' => t('Go to previous page')), - '#page_new' => pager_load_array($pager_page_array[$element] - 1, $element, $pager_page_array), - '#element' => $element, - '#interval' => 1, - '#parameters' => $parameters, + '#path' => $current_path, + '#options' => array( + 'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] - 1), + 'attributes' => array( + 'title' => t('Go to previous page'), + 'rel' => 'prev', + ), + ), ); } $li_next = array(); if ($pager_page_array[$element] < ($pager_total[$element] - 1)) { $li_next = array( - '#theme' => 'pager_link__next', + '#theme' => 'link__pager__next', '#text' => (isset($tags[3]) ? $tags[3] : t('››')), - '#attributes' => array('title' => t('Go to next page')), - '#page_new' => pager_load_array($pager_page_array[$element] + 1, $element, $pager_page_array), - '#element' => $element, - '#interval' => 1, - '#parameters' => $parameters, + '#path' => $current_path, + '#options' => array( + 'query' => pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1), + 'attributes' => array( + 'title' => t('Go to next page'), + 'rel' => 'next', + ), + ), ); } @@ -1186,7 +1192,7 @@ function theme_views_mini_pager($vars) { ) + $li_next; $item_list = array( - '#theme' => 'item_list', + '#theme' => 'item_list__pager', '#items' => $items, '#title' => NULL, '#type' => 'ul',