Allow specifying tag for current page number. Closes #2892

This commit is contained in:
ADmad 2012-10-12 20:13:45 +05:30
parent 57681ff115
commit 61dd1098d3
2 changed files with 31 additions and 3 deletions

View file

@ -1436,6 +1436,28 @@ class PaginatorHelperTest extends CakeTestCase {
);
$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',

View file

@ -650,6 +650,7 @@ class PaginatorHelper extends AppHelper {
* - `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.
@ -664,7 +665,8 @@ class PaginatorHelper extends AppHelper {
$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;
@ -678,7 +680,7 @@ class PaginatorHelper extends AppHelper {
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 = '';
@ -714,7 +716,11 @@ class PaginatorHelper extends AppHelper {
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;
}