mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-18 23:49:55 +00:00
Merge pull request #9896 from w1zardhead/add-crumb-prepend
Allow the prepend the addCrumb method
This commit is contained in:
commit
46bb71a536
2 changed files with 36 additions and 1 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -173,6 +173,10 @@ class HtmlHelper extends AppHelper {
|
||||||
/**
|
/**
|
||||||
* Adds a link to the breadcrumbs array.
|
* Adds a link to the breadcrumbs array.
|
||||||
*
|
*
|
||||||
|
* ### Options
|
||||||
|
*
|
||||||
|
* 'prepend' Prepend the breadcrumb to. Using this option
|
||||||
|
*
|
||||||
* @param string $name Text for link
|
* @param string $name Text for link
|
||||||
* @param string $link URL for link (if empty it won't be a 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')
|
* @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
|
* @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 = 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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue