Skip to content
Permalink
Browse files

Enhance HtmlHelper::getCrumbs() $startText param

It now accepts an array which gives more control and flexibilibity
over the first breadcrumb link.

Fixes #2475
  • Loading branch information...
markstory committed Jan 14, 2012
1 parent 7badb1d commit c89c49c3107978c14b14bb19d778e0f2e94cb536
Showing with 45 additions and 8 deletions.
  1. +25 −6 lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
  2. +20 −2 lib/Cake/View/Helper/HtmlHelper.php
@@ -866,7 +866,7 @@ public function testCharsetTag() {
}
/**
* testBreadcrumb method
* testGetCrumb and addCrumb method
*
* @return void
*/
@@ -909,11 +909,6 @@ public function testBreadcrumb() {
);
$this->assertTags($result, $expected);
$this->assertRegExp('/^<a[^<>]+>First<\/a> &gt; <a[^<>]+>Second<\/a> &gt; <a[^<>]+>Third<\/a>$/', $result);
$this->assertRegExp('/<a\s+href=["\']+\#first["\']+[^<>]*>First<\/a>/', $result);
$this->assertRegExp('/<a\s+href=["\']+\#second["\']+[^<>]*>Second<\/a>/', $result);
$this->assertRegExp('/<a\s+href=["\']+\#third["\']+[^<>]*>Third<\/a>/', $result);
$this->assertNotRegExp('/<a[^<>]+[^href]=[^<>]*>/', $result);
$this->Html->addCrumb('Fourth', null);
@@ -958,6 +953,30 @@ public function testBreadcrumb() {
$this->assertTags($result, $expected);
}
/**
* Test the array form of $startText
*/
public function testGetCrumbFirstLink() {
$this->Html->addCrumb('First', '#first');
$this->Html->addCrumb('Second', '#second');
$result = $this->Html->getCrumbs(' - ', array('url' => '/home', 'text' => '<img src="/home.png" />', 'escape' => false));
$expected = array(
array('a' => array('href' => '/home')),
'img' => array('src' => '/home.png'),
'/a',
' - ',
array('a' => array('href' => '#first')),
'First',
'/a',
' - ',
array('a' => array('href' => '#second')),
'Second',
'/a',
);
$this->assertTags($result, $expected);
}
/**
* testNestedList method
*
@@ -658,16 +658,34 @@ public function style($data, $oneline = true) {
/**
* Returns the breadcrumb trail as a sequence of &raquo;-separated links.
*
* If `$startText` is an array, the accepted keys are:
*
* - `text` Define the text/content for the link.
* - `url` Define the target of the created link.
*
* All other keys will be passed to HtmlHelper::link() as the `$options` parameter.
*
* @param string $separator Text to separate crumbs.
* @param string $startText This will be the first crumb, if false it defaults to first crumb in array
* @param mixed $startText This will be the first crumb, if false it defaults to first crumb in array. Can
* also be an array, see above for details.
* @return string Composed bread crumbs
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
*/
public function getCrumbs($separator = '&raquo;', $startText = false) {
if (!empty($this->_crumbs)) {
$out = array();
if ($startText) {
$out[] = $this->link($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']);
$out[] = $this->link($text, $url, $startText);
}
foreach ($this->_crumbs as $crumb) {

0 comments on commit c89c49c

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