mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-17 04:18:24 +00:00
Framework-compatible breadcrumbs
Add new options to getCrumbList to allow it to be used to make breadcrumbs in Twitter Bootstrap or Zurb foundation. Follows the model of PaginatorHelper
This commit is contained in:
parent
ed2f7013c9
commit
6f238a4048
1 changed files with 16 additions and 2 deletions
|
@ -681,6 +681,11 @@ class HtmlHelper extends AppHelper {
|
||||||
* similar to HtmlHelper::getCrumbs(), so it uses options which every
|
* similar to HtmlHelper::getCrumbs(), so it uses options which every
|
||||||
* crumb was added with.
|
* crumb was added with.
|
||||||
*
|
*
|
||||||
|
* ### Options
|
||||||
|
* - 'separator' Separator content to insert in between breadcrumbs, defaults to '»'
|
||||||
|
* - 'firstClass' Class for wrapper tag on the first breadcrumb, defaults to 'first'
|
||||||
|
* - 'lastClass' Class for wrapper tag on current active page, defaults to 'last'
|
||||||
|
*
|
||||||
* @param array $options Array of html attributes to apply to the generated list elements.
|
* @param array $options Array of html attributes to apply to the generated list elements.
|
||||||
* @param string|array|boolean $startText This will be the first crumb, if false it defaults to first crumb in array. Can
|
* @param string|array|boolean $startText This will be the first crumb, if false it defaults to first crumb in array. Can
|
||||||
* also be an array, see `HtmlHelper::getCrumbs` for details.
|
* also be an array, see `HtmlHelper::getCrumbs` for details.
|
||||||
|
@ -688,6 +693,12 @@ class HtmlHelper extends AppHelper {
|
||||||
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
|
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
|
||||||
*/
|
*/
|
||||||
public function getCrumbList($options = array(), $startText = false) {
|
public function getCrumbList($options = array(), $startText = false) {
|
||||||
|
$defaults = array('firstClass'=>'first', 'lastClass'=>'last', 'separator' => '');
|
||||||
|
$options += $defaults;
|
||||||
|
$firstClass = $options['firstClass'];
|
||||||
|
$lastClass = $options['lastClass'];
|
||||||
|
$separator = $options['separator'];
|
||||||
|
unset($options['firstClass'], $options['lastClass'], $options['separator']);
|
||||||
$crumbs = $this->_prepareCrumbs($startText);
|
$crumbs = $this->_prepareCrumbs($startText);
|
||||||
if (!empty($crumbs)) {
|
if (!empty($crumbs)) {
|
||||||
$result = '';
|
$result = '';
|
||||||
|
@ -701,9 +712,12 @@ class HtmlHelper extends AppHelper {
|
||||||
$elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
$elementContent = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
||||||
}
|
}
|
||||||
if ($which == 0) {
|
if ($which == 0) {
|
||||||
$options['class'] = 'first';
|
$options['class'] = $firstClass;
|
||||||
} elseif ($which == $crumbCount - 1) {
|
} elseif ($which == $crumbCount - 1) {
|
||||||
$options['class'] = 'last';
|
$options['class'] = $lastClass;
|
||||||
|
}
|
||||||
|
if (!empty($separator) && ($crumbCount - $which >= 2)) {
|
||||||
|
$elementContent .= $separator;
|
||||||
}
|
}
|
||||||
$result .= $this->tag('li', $elementContent, $options);
|
$result .= $this->tag('li', $elementContent, $options);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue