Skip to content
Permalink
Browse files

Allow the prepend the addCrumb method

  • Loading branch information...
stakahashi committed Dec 21, 2016
1 parent 4c3e935 commit 6f5b16b31fcc95274ad51d73975d3f4ccf732751
Showing with 33 additions and 2 deletions.
  1. +22 −0 lib/Cake/Test/Case/View/Helper/HtmlHelperTest.php
  2. +11 −2 lib/Cake/View/Helper/HtmlHelper.php
@@ -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);
}
/**
@@ -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;
}

0 comments on commit 6f5b16b

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