mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-01 23:29:45 +00:00
Merge pull request #483 from tigrang/getCrumbList-enhancement
Added `startText` feature to HtmlHelper::getCrumbList()
This commit is contained in:
commit
f138c73a77
2 changed files with 62 additions and 3 deletions
lib/Cake
|
@ -1785,6 +1785,50 @@ class HtmlHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test getCrumbList startText
|
||||||
|
*/
|
||||||
|
public function testCrumbListFirstLink() {
|
||||||
|
$this->Html->addCrumb('First', '#first');
|
||||||
|
$this->Html->addCrumb('Second', '#second');
|
||||||
|
|
||||||
|
$result = $this->Html->getCrumbList(null, 'Home');
|
||||||
|
$this->assertTags(
|
||||||
|
$result,
|
||||||
|
array(
|
||||||
|
'<ul',
|
||||||
|
array('li' => array('class' => 'first')),
|
||||||
|
array('a' => array('href' => '/')), 'Home', '/a',
|
||||||
|
'/li',
|
||||||
|
'<li',
|
||||||
|
array('a' => array('href' => '#first')), 'First', '/a',
|
||||||
|
'/li',
|
||||||
|
array('li' => array('class' => 'last')),
|
||||||
|
array('a' => array('href' => '#second')), 'Second', '/a',
|
||||||
|
'/li',
|
||||||
|
'/ul'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $this->Html->getCrumbList(null, array('url' => '/home', 'text' => '<img src="/home.png" />', 'escape' => false));
|
||||||
|
$this->assertTags(
|
||||||
|
$result,
|
||||||
|
array(
|
||||||
|
'<ul',
|
||||||
|
array('li' => array('class' => 'first')),
|
||||||
|
array('a' => array('href' => '/home')), 'img' => array('src' => '/home.png'), '/a',
|
||||||
|
'/li',
|
||||||
|
'<li',
|
||||||
|
array('a' => array('href' => '#first')), 'First', '/a',
|
||||||
|
'/li',
|
||||||
|
array('li' => array('class' => 'last')),
|
||||||
|
array('a' => array('href' => '#second')), 'Second', '/a',
|
||||||
|
'/li',
|
||||||
|
'/ul'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testLoadConfig method
|
* testLoadConfig method
|
||||||
*
|
*
|
||||||
|
|
|
@ -719,15 +719,30 @@ class HtmlHelper extends AppHelper {
|
||||||
* crumb was added with.
|
* crumb was added with.
|
||||||
*
|
*
|
||||||
* @param array $options Array of html attributes to apply to the generated list elements.
|
* @param array $options Array of html attributes to apply to the generated list elements.
|
||||||
|
* @param mixed $startText This will be the first crumb, if false it defaults to first crumb in array. Can
|
||||||
|
* also be an array, see `HtmlHelper::getCrumbs` for details.
|
||||||
* @return string breadcrumbs html list
|
* @return string breadcrumbs html list
|
||||||
* @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 getCrumbList($options = array()) {
|
public function getCrumbList($options = array(), $startText = false) {
|
||||||
if (!empty($this->_crumbs)) {
|
if (!empty($this->_crumbs)) {
|
||||||
$result = '';
|
$result = '';
|
||||||
$crumbCount = count($this->_crumbs);
|
$crumbs = $this->_crumbs;
|
||||||
|
if ($startText) {
|
||||||
|
if (!is_array($startText)) {
|
||||||
|
$startText = array(
|
||||||
|
'url' => '/',
|
||||||
|
'text' => $startText
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$startText += array('url' => '/', 'text' => __('Home'));
|
||||||
|
list($url, $text) = array($startText['url'], $startText['text']);
|
||||||
|
unset($startText['url'], $startText['text']);
|
||||||
|
array_unshift($crumbs, array($text, $url, $startText));
|
||||||
|
}
|
||||||
|
$crumbCount = count($crumbs);
|
||||||
$ulOptions = $options;
|
$ulOptions = $options;
|
||||||
foreach ($this->_crumbs as $which => $crumb) {
|
foreach ($crumbs as $which => $crumb) {
|
||||||
$options = array();
|
$options = array();
|
||||||
if (empty($crumb[1])) {
|
if (empty($crumb[1])) {
|
||||||
$elementContent = $crumb[0];
|
$elementContent = $crumb[0];
|
||||||
|
|
Loading…
Add table
Reference in a new issue