Skip to content

Commit 6f5b16b

Browse files
committed
Allow the prepend the addCrumb method
1 parent 4c3e935 commit 6f5b16b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,6 +1500,28 @@ public function testBreadcrumb() {
15001500
'Fourth'
15011501
);
15021502
$this->assertTags($result, $expected);
1503+
1504+
$this->Html->addCrumb('Zeroth', '#zeroth', array('prepend' => true));
1505+
1506+
$result = $this->Html->getCrumbs();
1507+
$expected = array(
1508+
array('a' => array('href' => '#zeroth')),
1509+
'Zeroth',
1510+
'/a',
1511+
'»',
1512+
array('a' => array('href' => '#first')),
1513+
'First',
1514+
'/a',
1515+
'»',
1516+
array('a' => array('href' => '#second')),
1517+
'Second',
1518+
'/a',
1519+
'»',
1520+
array('a' => array('href' => '#third')),
1521+
'Third',
1522+
'/a',
1523+
);
1524+
$this->assertTags($result, $expected);
15031525
}
15041526

15051527
/**

lib/Cake/View/Helper/HtmlHelper.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,17 @@ public function __construct(View $View, $settings = array()) {
180180
* @see HtmlHelper::link() for details on $options that can be used.
181181
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
182182
*/
183-
public function addCrumb($name, $link = null, $options = null) {
184-
$this->_crumbs[] = array($name, $link, $options);
183+
public function addCrumb($name, $link = null, $options = array()) {
184+
$prepend = false;
185+
if (isset($options['prepend'])) {
186+
$prepend = $options['prepend'];
187+
unset($options['prepend']);
188+
}
189+
if ($prepend) {
190+
array_unshift($this->_crumbs, array($name, $link, $options));
191+
} else {
192+
array_push($this->_crumbs, array($name, $link, $options));
193+
}
185194
return $this;
186195
}
187196

0 commit comments

Comments
 (0)