Skip to content
Permalink
Browse files

Allow customizing templates for prev() and next().

  • Loading branch information...
ADmad committed Aug 7, 2015
1 parent 999b0ef commit 058daad01c2eb82e323c498e9e8a8db8dcf65063
Showing with 53 additions and 2 deletions.
  1. +29 −2 src/View/Helper/PaginatorHelper.php
  2. +24 −0 tests/TestCase/View/Helper/PaginatorHelperTest.php
@@ -244,10 +244,24 @@ protected function _toggledLink($text, $enabled, $options, $templates)
}
$text = $options['escape'] ? h($text) : $text;
$templater = $this->templater();
$newTemplates = !empty($options['templates']) ? $options['templates'] : false;
if ($newTemplates) {
$templater->push();
$templateMethod = is_string($options['templates']) ? 'load' : 'add';
$templater->{$templateMethod}($options['templates']);
}
if (!$enabled) {
return $this->templater()->format($template, [
$out = $templater->format($template, [
'text' => $text,
]);
if ($newTemplates) {
$templater->pop();
}
return $out;
}
$paging = $this->params($options['model']);
@@ -256,10 +270,17 @@ protected function _toggledLink($text, $enabled, $options, $templates)
['page' => $paging['page'] + $options['step']]
);
$url = $this->generateUrl($url, $options['model']);
return $this->templater()->format($template, [
$out = $templater->format($template, [
'url' => $url,
'text' => $text,
]);
if ($newTemplates) {
$templater->pop();
}
return $out;
}
/**
@@ -273,6 +294,9 @@ protected function _toggledLink($text, $enabled, $options, $templates)
* - `escape` Whether you want the contents html entity encoded, defaults to true
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
* - `url` An array of additional URL options to use for link generation.
* - `templates` An array of templates, or template file name containing the
* templates you'd like to use when generating the link for previous page.
* The helper's original templates will be restored once prev() is done.
*
* @param string $title Title for the link. Defaults to '<< Previous'.
* @param array $options Options for pagination link. See above for list of keys.
@@ -309,6 +333,9 @@ public function prev($title = '<< Previous', array $options = [])
* - `escape` Whether you want the contents html entity encoded, defaults to true
* - `model` The model to use, defaults to PaginatorHelper::defaultModel()
* - `url` An array of additional URL options to use for link generation.
* - `templates` An array of templates, or template file name containing the
* templates you'd like to use when generating the link for next page.
* The helper's original templates will be restored once next() is done.
*
* @param string $title Title for the link. Defaults to 'Next >>'.
* @param array $options Options for pagination link. See above for list of keys.
@@ -915,6 +915,18 @@ public function testPrev()
'/li'
];
$this->assertHtml($expected, $result);
$result = $this->Paginator->prev('Prev', [
'templates' => [
'prevActive' => '<a rel="prev" href="{{url}}">{{text}}</a>'
]
]);
$expected = [
'a' => ['href' => '/index', 'rel' => 'prev'],
'Prev',
'/a',
];
$this->assertHtml($expected, $result);
}
/**
@@ -960,6 +972,18 @@ public function testNext()
];
$this->assertHtml($expected, $result);
$result = $this->Paginator->next('Next', [
'templates' => [
'nextActive' => '<a rel="next" href="{{url}}">{{text}}</a>'
]
]);
$expected = [
'a' => ['href' => '/index?page=2', 'rel' => 'next'],
'Next',
'/a',
];
$this->assertHtml($expected, $result);
$result = $this->Paginator->next('Next >>', ['escape' => false]);
$expected = [
'li' => ['class' => 'next'],

0 comments on commit 058daad

Please sign in to comment.
You can’t perform that action at this time.