diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/pager/Mini.php b/core/modules/views/lib/Drupal/views/Plugin/views/pager/Mini.php index 4783b2a..5038746 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/pager/Mini.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/pager/Mini.php @@ -24,6 +24,40 @@ */ class Mini extends Full { + /** + * Overrides \Drupal\views\Plugin\views\pager\Full::defineOptions(). + * + * Overrides the full pager options form by deleting unused settings. + */ + public function defineOptions() { + $options = parent::defineOptions(); + + unset($options['quantity']); + unset($options['tags']['first']); + unset($options['tags']['last']); + $options['tags']['contains']['previous']['default'] = '‹‹'; + $options['tags']['contains']['next']['default'] = '››'; + + return $options; + } + + /** + * Overrides \Drupal\views\Plugin\views\pager\Full::buildOptionsForm(). + * + * Overrides the full pager options form by deleting unused settings. + */ + public function buildOptionsForm(&$form, &$form_state) { + parent::buildOptionsForm($form, $form_state); + + unset($form['quantity']); + unset($form['tags']['first']); + unset($form['tags']['last']); + } + + + /** + * Overrides \Drupal\views\Plugin\views\pager\Full::summaryTitle(). + */ public function summaryTitle() { if (!empty($this->options['offset'])) { return format_plural($this->options['items_per_page'], 'Mini pager, @count item, skip @skip', 'Mini pager, @count items, skip @skip', array('@count' => $this->options['items_per_page'], '@skip' => $this->options['offset'])); @@ -31,10 +65,22 @@ public function summaryTitle() { return format_plural($this->options['items_per_page'], 'Mini pager, @count item', 'Mini pager, @count items', array('@count' => $this->options['items_per_page'])); } + /** + * Overrides \Drupal\views\Plugin\views\pager\Full::render(). + */ function render($input) { $pager_theme = views_theme_functions('views_mini_pager', $this->view, $this->view->display_handler->display); - return theme($pager_theme, array( - 'parameters' => $input, 'element' => $this->options['id'])); + // The 1, 3 index are correct, see theme_pager(). + $tags = array( + 1 => $this->options['tags']['previous'], + 3 => $this->options['tags']['next'], + ); + $output = theme($pager_theme, array( + 'parameters' => $input, + 'element' => $this->options['id'], + 'tags' => $tags, + )); + return $output; } } diff --git a/core/modules/views/lib/Drupal/views/Tests/Plugin/MiniPagerTest.php b/core/modules/views/lib/Drupal/views/Tests/Plugin/MiniPagerTest.php new file mode 100644 index 0000000..f88f628 --- /dev/null +++ b/core/modules/views/lib/Drupal/views/Tests/Plugin/MiniPagerTest.php @@ -0,0 +1,59 @@ + 'Pager: Mini', + 'description' => 'Test the mini pager plugin.', + 'group' => 'Views Plugins', + ); + } + + protected function setUp() { + parent::setUp(); + + // Create a bunch of test nodes. + for ($i = 0; $i < 20; $i++) { + $this->nodes[] = $this->drupalCreateNode(); + } + } + + /** + * Tests the rendering of mini pagers. + */ + public function testMiniPagerRender() { + menu_router_rebuild(); + $this->drupalGet('test_mini_pager'); + $this->assertText('›› test', 'Make sure the next link appears on the first page.'); + $this->assertNoText('‹‹ test', 'Make sure the previous link does not appear on the first page.'); + + $this->drupalGet('test_mini_pager', array('query' => array('page' => 1))); + $this->assertText('‹‹ test', 'Make sure the previous link appears.'); + $this->assertText('›› test', 'Make sure the next link appears.'); + + $this->drupalGet('test_mini_pager', array('query' => array('page' => 6))); + $this->assertNoText('›› test', 'Make sure the next link appears on the last page.'); + $this->assertText('‹‹ test', 'Make sure the previous link does not appear on the last page.'); + } + +} diff --git a/core/modules/views/tests/views_test_config/config/views.view.test_mini_pager.yml b/core/modules/views/tests/views_test_config/config/views.view.test_mini_pager.yml new file mode 100644 index 0000000..4dfa3f7 --- /dev/null +++ b/core/modules/views/tests/views_test_config/config/views.view.test_mini_pager.yml @@ -0,0 +1,83 @@ +base_table: node +name: test_mini_pager +description: '' +tag: '' +human_name: test_mini_pager +core: 8.x +api_version: '3.0' +display: + default: + display_plugin: default + id: default + display_title: Master + position: '' + display_options: + access: + type: perm + cache: + type: none + query: + type: views_query + exposed_form: + type: basic + pager: + type: mini + options: + items_per_page: '3' + offset: '0' + id: '0' + total_pages: '' + tags: + previous: ‹‹ test + next: ›› test + expose: + items_per_page: '0' + items_per_page_label: 'Items per page' + items_per_page_options: '5, 10, 20, 40, 60' + items_per_page_options_all: '0' + items_per_page_options_all_label: '- All -' + offset: '0' + offset_label: Offset + style: + type: default + row: + type: node + options: + build_mode: teaser + links: '1' + comments: '0' + fields: + title: + id: title + table: node + field: title + label: '' + alter: + alter_text: '0' + make_link: '0' + absolute: '0' + trim: '0' + word_boundary: '0' + ellipsis: '0' + strip_tags: '0' + html: '0' + hide_empty: '0' + empty_zero: '0' + link_to_node: '1' + filters: { } + sorts: { } + title: test_mini_pager + filter_groups: + operator: AND + groups: { } + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: '' + display_options: + path: test_mini_pager +base_field: nid +disabled: '0' +module: views +langcode: und diff --git a/core/modules/views/theme/theme.inc b/core/modules/views/theme/theme.inc index 0a45642..14f9fcd 100644 --- a/core/modules/views/theme/theme.inc +++ b/core/modules/views/theme/theme.inc @@ -1050,65 +1050,64 @@ function theme_views_mini_pager($vars) { $parameters = $vars['parameters']; $quantity = $vars['quantity']; - // Calculate various markers within this pager piece: - // Middle is used to "center" pages around the current page. - $pager_middle = ceil($quantity / 2); // current is the page we are currently paged to $pager_current = $pager_page_array[$element] + 1; // max is the maximum page number $pager_max = $pager_total[$element]; // End of marker calculations. - if ($pager_total[$element] > 1) { - - $li_previous = theme('pager_previous', + if ($pager_total[$element] > 1 && $pager_page_array[$element] > 0) { + $li_previous = theme('pager_link__previous', array( 'text' => (isset($tags[1]) ? $tags[1] : t('‹‹')), + 'page_new' => pager_load_array($pager_page_array[$element] - 1, $element, $pager_page_array), 'element' => $element, 'interval' => 1, 'parameters' => $parameters, ) ); - if (empty($li_previous)) { - $li_previous = " "; - } + } + else { + $li_previous = " "; + } - $li_next = theme('pager_next', + if ($pager_page_array[$element] < ($pager_total[$element] - 1)) { + $li_next = theme('pager_link__next', array( 'text' => (isset($tags[3]) ? $tags[3] : t('››')), + 'page_new' => pager_load_array($pager_page_array[$element] + 1, $element, $pager_page_array), 'element' => $element, 'interval' => 1, 'parameters' => $parameters, ) ); - - if (empty($li_next)) { - $li_next = " "; - } - - $items[] = array( - 'class' => array('pager-previous'), - 'data' => $li_previous, - ); - - $items[] = array( - 'class' => array('pager-current'), - 'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)), - ); - - $items[] = array( - 'class' => array('pager-next'), - 'data' => $li_next, - ); - return theme('item_list', - array( - 'items' => $items, - 'title' => NULL, - 'type' => 'ul', - 'attributes' => array('class' => array('pager')), - ) - ); } + else { + $li_next = " "; + } + + $items[] = array( + 'class' => array('pager-previous'), + 'data' => $li_previous, + ); + + $items[] = array( + 'class' => array('pager-current'), + 'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)), + ); + + $items[] = array( + 'class' => array('pager-next'), + 'data' => $li_next, + ); + return theme('item_list', + array( + 'items' => $items, + 'title' => NULL, + 'type' => 'ul', + 'attributes' => array('class' => array('pager')), + ) + ); } /**