Skip to content

Commit

Permalink
Allow the prepend the addCrumb method
Browse files Browse the repository at this point in the history
  • Loading branch information
stakahashi committed Dec 21, 2016
1 parent 4c3e935 commit 6f5b16b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
22 changes: 22 additions & 0 deletions lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
Expand Up @@ -1500,6 +1500,28 @@ public function testBreadcrumb() {
'Fourth'
);
$this->assertTags($result, $expected);

$this->Html->addCrumb('Zeroth', '#zeroth', array('prepend' => true));

$result = $this->Html->getCrumbs();
$expected = array(
array('a' => array('href' => '#zeroth')),
'Zeroth',
'/a',
'»',
array('a' => array('href' => '#first')),
'First',
'/a',
'»',
array('a' => array('href' => '#second')),
'Second',
'/a',
'»',
array('a' => array('href' => '#third')),
'Third',
'/a',
);
$this->assertTags($result, $expected);
}

/**
Expand Down
13 changes: 11 additions & 2 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -180,8 +180,17 @@ public function __construct(View $View, $settings = array()) {
* @see HtmlHelper::link() for details on $options that can be used.
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
*/
public function addCrumb($name, $link = null, $options = null) {
$this->_crumbs[] = array($name, $link, $options);
public function addCrumb($name, $link = null, $options = array()) {
$prepend = false;
if (isset($options['prepend'])) {
$prepend = $options['prepend'];
unset($options['prepend']);
}
if ($prepend) {
array_unshift($this->_crumbs, array($name, $link, $options));
} else {
array_push($this->_crumbs, array($name, $link, $options));
}
return $this;
}

Expand Down

0 comments on commit 6f5b16b

Please sign in to comment.