Skip to content

Commit

Permalink
Allow specifying tag for current page number. Closes #2892
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Oct 13, 2012
1 parent 57681ff commit 61dd109
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
22 changes: 22 additions & 0 deletions lib/Cake/Test/Case/View/Helper/PaginatorHelperTest.php
Expand Up @@ -1436,6 +1436,28 @@ public function testNumbers() {
);
$this->assertTags($result, $expected);

$result = $this->Paginator->numbers(array('first' => 1, 'tag' => 'li', 'currentClass' => 'active', 'currentTag' => 'a'));
$expected = array(
array('li' => array()), array('a' => array('href' => '/index/page:1')), '1', '/a', '/li',
' | ',
array('li' => array('class' => 'active')), array('a' => array()), '2', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:3')), '3', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:4')), '4', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:5')), '5', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:6')), '6', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:7')), '7', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:8')), '8', '/a', '/li',
' | ',
array('li' => array()), array('a' => array('href' => '/index/page:9')), '9', '/a', '/li',
);
$this->assertTags($result, $expected);

$result = $this->Paginator->numbers(array('first' => 1, 'class' => 'page-link', 'currentClass' => 'active'));
$expected = array(
array('span' => array('class' => 'page-link')), array('a' => array('href' => '/index/page:1')), '1', '/a', '/span',
Expand Down
12 changes: 9 additions & 3 deletions lib/Cake/View/Helper/PaginatorHelper.php
Expand Up @@ -650,6 +650,7 @@ public function counter($options = array()) {
* - `ellipsis` Ellipsis content, defaults to '...'
* - `class` Class for wrapper tag
* - `currentClass` Class for wrapper tag on current active page, defaults to 'current'
* - `currentTag` Tag to use for current page number, defaults to null
*
* @param array $options Options for the numbers, (before, after, model, modulus, separator)
* @return string numbers string.
Expand All @@ -664,7 +665,8 @@ public function numbers($options = array()) {

$defaults = array(
'tag' => 'span', 'before' => null, 'after' => null, 'model' => $this->defaultModel(), 'class' => null,
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...', 'currentClass' => 'current'
'modulus' => '8', 'separator' => ' | ', 'first' => null, 'last' => null, 'ellipsis' => '...',
'currentClass' => 'current', 'currentTag' => null
);
$options += $defaults;

Expand All @@ -678,7 +680,7 @@ public function numbers($options = array()) {
extract($options);
unset($options['tag'], $options['before'], $options['after'], $options['model'],
$options['modulus'], $options['separator'], $options['first'], $options['last'],
$options['ellipsis'], $options['class'], $options['currentClass']
$options['ellipsis'], $options['class'], $options['currentClass'], $options['currentTag']
);

$out = '';
Expand Down Expand Up @@ -714,7 +716,11 @@ public function numbers($options = array()) {
if ($class) {
$currentClass .= ' ' . $class;
}
$out .= $this->Html->tag($tag, $params['page'], array('class' => $currentClass));
if ($currentTag) {
$out .= $this->Html->tag($tag, $this->Html->tag($currentTag, $params['page']), array('class' => $currentClass));
} else {
$out .= $this->Html->tag($tag, $params['page'], array('class' => $currentClass));
}
if ($i != $params['pageCount']) {
$out .= $separator;
}
Expand Down

0 comments on commit 61dd109

Please sign in to comment.