Merge pull request #9896 from w1zardhead/add-crumb-prepend

Allow the prepend the addCrumb method
This commit is contained in:
Mark Story 2017-01-03 11:00:33 -05:00 committed by GitHub
commit 46bb71a536
2 changed files with 36 additions and 1 deletions

View file

@ -1500,6 +1500,28 @@ class HtmlHelperTest extends CakeTestCase {
'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);
}
/**

View file

@ -173,6 +173,10 @@ class HtmlHelper extends AppHelper {
/**
* Adds a link to the breadcrumbs array.
*
* ### Options
*
* 'prepend' Prepend the breadcrumb to. Using this option
*
* @param string $name Text for link
* @param string $link URL for link (if empty it won't be a link)
* @param string|array $options Link attributes e.g. array('id' => 'selected')
@ -181,7 +185,16 @@ class HtmlHelper extends AppHelper {
* @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);
$prepend = false;
if (is_array($options) && 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;
}