Allow the prepend the addCrumb method

This commit is contained in:
Shunsuke Takahashi 2016-12-21 16:34:35 +09:00
parent 4c3e9356ba
commit 6f5b16b31f
2 changed files with 33 additions and 2 deletions

View file

@ -1500,6 +1500,28 @@ class HtmlHelperTest extends CakeTestCase {
'Fourth' 'Fourth'
); );
$this->assertTags($result, $expected); $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

@ -180,8 +180,17 @@ class HtmlHelper extends AppHelper {
* @see HtmlHelper::link() for details on $options that can be used. * @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 * @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) { public function addCrumb($name, $link = null, $options = array()) {
$this->_crumbs[] = array($name, $link, $options); $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; return $this;
} }