Skip to content

Commit

Permalink
Merge pull request #483 from tigrang/getCrumbList-enhancement
Browse files Browse the repository at this point in the history
Added `startText` feature to HtmlHelper::getCrumbList()
  • Loading branch information
markstory committed Feb 22, 2012
2 parents 6684b77 + af2fd03 commit f138c73
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
44 changes: 44 additions & 0 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -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
*
Expand Down
21 changes: 18 additions & 3 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -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];
Expand Down

0 comments on commit f138c73

Please sign in to comment.