Fix getCrumbs() with no crumbs and first link.

Apply patch from 'Andy Hobbs' to fix issues with breadcrumbs, and
a starting breadcrumb.

Fixes #2689
This commit is contained in:
mark_story 2012-03-17 23:23:42 -04:00
parent d0733ceb00
commit c54ac257f1
2 changed files with 16 additions and 4 deletions

View file

@ -1161,6 +1161,18 @@ class HtmlHelperTest extends CakeTestCase {
* Test the array form of $startText
*/
public function testGetCrumbFirstLink() {
$result = $this->Html->getCrumbList(null, 'Home');
$this->assertTags(
$result,
array(
'<ul',
array('li' => array('class' => 'first')),
array('a' => array('href' => '/')), 'Home', '/a',
'/li',
'/ul'
)
);
$this->Html->addCrumb('First', '#first');
$this->Html->addCrumb('Second', '#second');

View file

@ -671,9 +671,9 @@ class HtmlHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
*/
public function getCrumbs($separator = '&raquo;', $startText = false) {
if (!empty($this->_crumbs)) {
$crumbs = $this->_prepareCrumbs($startText);
if (!empty($crumbs)) {
$out = array();
$crumbs = $this->_prepareCrumbs($startText);
foreach ($crumbs as $crumb) {
if (!empty($crumb[1])) {
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
@ -701,9 +701,9 @@ class HtmlHelper extends AppHelper {
* @link http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html#creating-breadcrumb-trails-with-htmlhelper
*/
public function getCrumbList($options = array(), $startText = false) {
if (!empty($this->_crumbs)) {
$crumbs = $this->_prepareCrumbs($startText);
if (!empty($crumbs)) {
$result = '';
$crumbs = $this->_prepareCrumbs($startText);
$crumbCount = count($crumbs);
$ulOptions = $options;
foreach ($crumbs as $which => $crumb) {