Skip to content
Permalink
Browse files

Added `startText` feature to HtmlHelper::getCrumbList()

  • Loading branch information...
tigrang committed Feb 17, 2012
1 parent bda0529 commit af2fd0359072eebccc68f5bbc8e7ddfd6c1af829
Showing with 62 additions and 3 deletions.
  1. +44 −0 lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
  2. +18 −3 lib/Cake/View/Helper/HtmlHelper.php
@@ -1785,6 +1785,50 @@ public function testCrumbList() {
);
}
/**
* Test getCrumbList startText
*/
public function testCrumbListFirstLink() {
$this->Html->addCrumb('First', '#first');
$this->Html->addCrumb('Second', '#second');
$result = $this->Html->getCrumbList(null, 'Home');
$this->assertTags(
$result,
array(
'<ul',
array('li' => array('class' => 'first')),
array('a' => array('href' => '/')), 'Home', '/a',
'/li',
'<li',
array('a' => array('href' => '#first')), 'First', '/a',
'/li',
array('li' => array('class' => 'last')),
array('a' => array('href' => '#second')), 'Second', '/a',
'/li',
'/ul'
)
);
$result = $this->Html->getCrumbList(null, array('url' => '/home', 'text' => '<img src="/home.png" />', 'escape' => false));
$this->assertTags(
$result,
array(
'<ul',
array('li' => array('class' => 'first')),
array('a' => array('href' => '/home')), 'img' => array('src' => '/home.png'), '/a',
'/li',
'<li',
array('a' => array('href' => '#first')), 'First', '/a',
'/li',
array('li' => array('class' => 'last')),
array('a' => array('href' => '#second')), 'Second', '/a',
'/li',
'/ul'
)
);
}
/**
* testLoadConfig method
*
@@ -719,15 +719,30 @@ public function getCrumbs($separator = '&raquo;', $startText = false) {
* crumb was added with.
*
* @param array $options Array of html attributes to apply to the generated list elements.
* @param mixed $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.
* @return string breadcrumbs html list
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
*/
public function getCrumbList($options = array()) {
public function getCrumbList($options = array(), $startText = false) {
if (!empty($this->_crumbs)) {
$result = '';
$crumbCount = count($this->_crumbs);
$crumbs = $this->_crumbs;
if ($startText) {
if (!is_array($startText)) {
$startText = array(
'url' => '/',
'text' => $startText
);
}
$startText += array('url' => '/', 'text' => __('Home'));
list($url, $text) = array($startText['url'], $startText['text']);
unset($startText['url'], $startText['text']);
array_unshift($crumbs, array($text, $url, $startText));
}
$crumbCount = count($crumbs);
$ulOptions = $options;
foreach ($this->_crumbs as $which => $crumb) {
foreach ($crumbs as $which => $crumb) {
$options = array();
if (empty($crumb[1])) {
$elementContent = $crumb[0];

0 comments on commit af2fd03

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