diff --git a/core/includes/pager.inc b/core/includes/pager.inc index 780ff6f..ed6f90f 100644 --- a/core/includes/pager.inc +++ b/core/includes/pager.inc @@ -182,16 +182,6 @@ function template_preprocess_pager(&$variables) { 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); @@ -223,193 +213,59 @@ 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( - '#type' => 'link', - '#title' => $tags[0], - '#href' => $current_path, - '#options' => array( - 'query' => pager_query_add_page($parameters, $element, 0), - 'attributes' => array( - 'title' => t('Go to first page'), - 'rel' => 'first', - ), - // Below is ignored by default, supplied to support hook_link_alter - // implementations. - 'pager_context' => array( - 'link_type' => 'first', - 'element' => $element, - ), - ), - ); - $li_previous = array( - '#type' => 'link', - '#title' => $tags[1], - '#href' => $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', - ), - // Below is ignored by default, supplied to support hook_link_alter - // implementations. - 'pager_context' => array( - 'link_type' => 'previous', - 'element' => $element, - ), - ), - ); - } - - // 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( - '#type' => 'link', - '#title' => $tags[3], - '#href' => $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', - ), - // Below is ignored by default, supplied to support hook_link_alter - // implementations. - 'pager_context' => array( - 'link_type' => 'next', - 'element' => $element, - ), - ), - ); - $li_last = array( - '#type' => 'link', - '#title' => $tags[4], - '#href' => $current_path, - '#options' => array( - 'query' => pager_query_add_page($parameters, $element, $pager_total[$element] - 1), - 'attributes' => array( - 'title' => t('Go to last page'), - 'rel' => 'last', - ), - // Below is ignored by default, supplied to support hook_link_alter - // implementations. - 'pager_context' => array( - 'link_type' => 'last', - 'element' => $element, - ), - ), - ); - } + //$current_path = current_path(); + $ellipsis = array(); if ($pager_total[$element] > 1) { - if ($li_first) { - $items[] = array( - '#wrapper_attributes' => array('class' => array('pager-first')), - 'link' => $li_first, - ); - } - if ($li_previous) { - $items[] = array( - '#wrapper_attributes' => array('class' => array('pager-previous')), - 'link' => $li_previous, - ); + // Create the "first" and "previous" links if we are not on the first page. + if ($pager_page_array[$element] > 0) { + $items['first'] = true; + $li_previous = pager_query_add_page($parameters, $element, $pager_page_array[$element] - 1); + if ($li_previous && isset($li_previous['page'])) { + $items['previous'] = $li_previous['page']; + } } - // When there is more than one page, create the pager list. if ($i != $pager_max) { // Check whether there are further previous pages. if ($i > 1) { - $items[] = array( - '#wrapper_attributes' => array('class' => array('pager-ellipsis')), - '#markup' => '…', - ); + $ellipsis['prev'] = true; } // Now generate the actual pager piece. for (; $i <= $pager_last && $i <= $pager_max; $i++) { - if ($i < $pager_current) { - $items[] = array( - '#wrapper_attributes' => array('class' => array('pager-item')), - 'link' => array( - '#type' => 'link', - '#title' => $i, - '#href' => $current_path, - '#options' => array( - 'query' => pager_query_add_page($parameters, $element, $i - 1), - 'attributes' => array( - 'title' => t('Go to page @number', array('@number' => $i)), - ), - // Below is ignored by default, supplied to support hook_link_alter - // implementations. - 'pager_context' => array( - 'link_type' => 'item', - 'element' => $element, - 'interval' => ($pager_current - $i), - ), - ), - ), - ); - } - if ($i == $pager_current) { - $items[] = array( - '#wrapper_attributes' => array('class' => array('pager-current')), - '#markup' => $i, - ); - } - if ($i > $pager_current) { - $items[] = array( - '#wrapper_attributes' => array('class' => array('pager-item')), - 'link' => array( - '#type' => 'link', - '#title' => $i, - '#href' => $current_path, - '#options' => array( - 'query' => pager_query_add_page($parameters, $element, $i - 1), - 'attributes' => array( - 'title' => t('Go to page @number', array('@number' => $i)), - ), - // Below is ignored by default, supplied to support hook_link_alter - // implementations. - 'pager_context' => array( - 'link_type' => 'item', - 'element' => $element, - 'interval' => ($i - $pager_current), - ), - ), - ), - ); + $query = pager_query_add_page($parameters, $element, $i); + if (isset($query['page'])) { + $items['pages'][$i-1] = $query['page']; } } // Check whether there are further next pages. if ($i < $pager_max) { - $items[] = array( - '#wrapper_attributes' => array('class' => array('pager-ellipsis')), - '#markup' => '…', - ); + $ellipsis['next'] = true; } } - // End generation. - if ($li_next) { - $items[] = array( - '#wrapper_attributes' => array('class' => array('pager-next')), - 'link' => $li_next, - ); + // 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 = pager_query_add_page($parameters, $element, $pager_page_array[$element] + 1); + $li_last = pager_query_add_page($parameters, $element, $pager_total[$element] - 1); + // End generation. + if ($li_next) { + $items['next'] = $li_next['page']; + } + if ($li_last) { + $items['last'] = $li_last['page']; + } } - if ($li_last) { - $items[] = array( - '#wrapper_attributes' => array('class' => array('pager-last')), - 'link' => $li_last, - ); + // Get uri + $uri = \Drupal::request()->getRequestUri(); + // Strip pager querystring because it gets added back in pager.html.twig but leave it otherwise for ajax calls + if (strpos($uri,'?page=') !== FALSE) { + $variables['current_path'] = strstr($uri, '?page=', TRUE); + } else { + $variables['current_path'] = $uri; } - - $variables['items'] = array( - '#theme' => 'item_list__pager', - '#items' => $items, - '#attributes' => array('class' => array('pager')), - ); + $variables['pager_current'] = $pager_current; + $variables['items'] = $items; + $variables['ellipsis'] = $ellipsis; } } diff --git a/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php b/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php index 161d215..b27d4e0 100644 --- a/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php +++ b/core/modules/aggregator/src/Tests/AggregatorRenderingTest.php @@ -95,7 +95,7 @@ public function testFeedPage() { // Check for presence of an aggregator pager. $this->drupalGet('aggregator'); - $elements = $this->xpath("//ul[@class=:class]", array(':class' => 'pager')); + $elements = $this->xpath("//ul[@class=:class]", array(':class' => 'pager__items')); $this->assertTrue(!empty($elements), 'Individual source page contains a pager.'); // Check for sources page title. @@ -110,7 +110,7 @@ public function testFeedPage() { // Check for the presence of a pager. $this->drupalGet('aggregator/sources/' . $feed->id()); - $elements = $this->xpath("//ul[@class=:class]", array(':class' => 'pager')); + $elements = $this->xpath("//ul[@class=:class]", array(':class' => 'pager__items')); $this->assertTrue(!empty($elements), 'Individual source page contains a pager.'); } } diff --git a/core/modules/comment/src/Tests/CommentPagerTest.php b/core/modules/comment/src/Tests/CommentPagerTest.php index f712ce0..152db57 100644 --- a/core/modules/comment/src/Tests/CommentPagerTest.php +++ b/core/modules/comment/src/Tests/CommentPagerTest.php @@ -334,19 +334,19 @@ function testTwoPagers() { $this->assertRaw('Comment 1 on field comment'); $this->assertRaw('Comment 1 on field comment_2'); // Navigate to next page of field 1. - $this->clickLink('next ›'); + $this->clickLink('Next page'); // Check only one pager updated. $this->assertRaw('Comment 2 on field comment'); $this->assertRaw('Comment 1 on field comment_2'); // Return to page 1. $this->drupalGet('node/' . $node->id()); // Navigate to next page of field 2. - $this->clickLink('next ›', 1); + $this->clickLink('Next page', 1); // Check only one pager updated. $this->assertRaw('Comment 1 on field comment'); $this->assertRaw('Comment 2 on field comment_2'); // Navigate to next page of field 1. - $this->clickLink('next ›'); + $this->clickLink('Next page'); // Check only one pager updated. $this->assertRaw('Comment 2 on field comment'); $this->assertRaw('Comment 2 on field comment_2'); diff --git a/core/modules/system/src/Tests/Pager/PagerTest.php b/core/modules/system/src/Tests/Pager/PagerTest.php index 845aa28..4833149 100644 --- a/core/modules/system/src/Tests/Pager/PagerTest.php +++ b/core/modules/system/src/Tests/Pager/PagerTest.php @@ -60,10 +60,12 @@ function testActiveClass() { $this->assertPagerItems($current_page); // Verify last page. - $elements = $this->xpath('//li[contains(@class, :class)]/a', array(':class' => 'pager-last')); - preg_match('@page=(\d+)@', $elements[0]['href'], $matches); + $elements = $this->xpath('//li/a[contains(.,"Last page")]'); + $attributes = $elements[0]->attributes(); + $href = $attributes['href']; + preg_match('@page=(\d+)@', $href, $matches); $current_page = (int) $matches[1]; - $this->drupalGet($GLOBALS['base_root'] . $elements[0]['href'], array('external' => TRUE)); + $this->drupalGet('admin/reports/dblog', array('query' => array('page' => $current_page))); $this->assertPagerItems($current_page); } @@ -74,7 +76,7 @@ function testActiveClass() { * The current pager page the internal browser is on. */ protected function assertPagerItems($current_page) { - $elements = $this->xpath('//ul[@class=:class]/li', array(':class' => 'pager')); + $elements = $this->xpath('//ul[@class=:class]/li', array(':class' => 'pager__items')); $this->assertTrue(!empty($elements), 'Pager found.'); // Make current page 1-based. @@ -97,14 +99,14 @@ protected function assertPagerItems($current_page) { // Make item/page index 1-based. $page++; if ($current_page == $page) { - $this->assertClass($element, 'pager-current', 'Item for current page has .pager-current class.'); - $this->assertFalse(isset($element->a), 'Item for current page has no link.'); + $this->assertClass($element, 'is-active', 'Item for current page has .is-active class.'); + $this->assertTrue(isset($element->a), 'Item for current page has link.'); } else { - $this->assertNoClass($element, 'pager-current', "Item for page $page has no .pager-current class."); - $this->assertClass($element, 'pager-item', "Item for page $page has .pager-item class."); + $this->assertNoClass($element, 'is-active', "Item for page $page has no .is-active class."); + //$this->assertClass($element, 'pager-item', "Item for page $page has .pager-item class."); $this->assertTrue($element->a, "Link to page $page found."); - $this->assertNoClass($element->a, 'active', "Link to page $page is not active."); + //$this->assertNoClass($element, 'is-active', "Link to page $page is not active."); } unset($elements[--$page]); } @@ -113,24 +115,20 @@ protected function assertPagerItems($current_page) { // Verify first/previous and next/last items and links. if (isset($first)) { - $this->assertClass($first, 'pager-first', 'Item for first page has .pager-first class.'); + $this->assertClass($first->a->i, 'icon--go-first', 'Item for first page has .icon--go-first class.'); $this->assertTrue($first->a, 'Link to first page found.'); - $this->assertNoClass($first->a, 'active', 'Link to first page is not active.'); } if (isset($previous)) { - $this->assertClass($previous, 'pager-previous', 'Item for first page has .pager-previous class.'); + $this->assertClass($previous->a->i, 'icon--go-previous', 'Item for first page has .icon--go-previous class.'); $this->assertTrue($previous->a, 'Link to previous page found.'); - $this->assertNoClass($previous->a, 'active', 'Link to previous page is not active.'); } if (isset($next)) { - $this->assertClass($next, 'pager-next', 'Item for next page has .pager-next class.'); + $this->assertClass($next->a->i, 'icon--go-next', 'Item for next page has .icon--go-next class.'); $this->assertTrue($next->a, 'Link to next page found.'); - $this->assertNoClass($next->a, 'active', 'Link to next page is not active.'); } if (isset($last)) { - $this->assertClass($last, 'pager-last', 'Item for last page has .pager-last class.'); + $this->assertClass($last->a->i, 'icon--go-last', 'Item for last page has .icon--go-last class.'); $this->assertTrue($last->a, 'Link to last page found.'); - $this->assertNoClass($last->a, 'active', 'Link to last page is not active.'); } } diff --git a/core/modules/system/templates/pager.html.twig b/core/modules/system/templates/pager.html.twig index 47b20a7..5c93fe4 100644 --- a/core/modules/system/templates/pager.html.twig +++ b/core/modules/system/templates/pager.html.twig @@ -12,6 +12,34 @@ */ #} {% if items %} -