Skip to content
Permalink
Browse files

Added HtmlHelper::getCrumbList() to generate semantically correct

(x)html breadcrumb navigation path and a test to it. Fixes #856

Signed-off-by: mark_story <mark@mark-story.com>
  • Loading branch information...
shazarre authored and markstory committed Jun 27, 2010
1 parent cb3100f commit 68a9c9c5aba2bcbc4a2ce34856d0425c0364b5df
Showing with 85 additions and 0 deletions.
  1. +49 −0 cake/libs/view/helpers/html.php
  2. +36 −0 cake/tests/cases/libs/view/helpers/html.test.php
@@ -578,6 +578,55 @@ public function getCrumbs($separator = '&raquo;', $startText = false) {
}
}
/**
* Returns breadcrumbs as a (x)html list
*
* This method uses HtmlHelper::tag() to generate list and its elements. Works
* similiary to HtmlHelper::getCrumbs(), so it uses options which every
* crumb was added with.
*
* @param array $list_options options to render list
*
* @return string breadcrumbs html list
*
* @access public
*/
function getCrumbList($list_options = array()) {
if (!empty($this->_crumbs)) {
$result = '';
$crumb_count = count($this->_crumbs);
foreach ($this->_crumbs as $which => $crumb) {
$options = array();
if (empty($crumb[1])) {
$element_content = $crumb[0];
} else {
$element_content = $this->link(
$crumb[0],
$crumb[1],
$crumb[2]
);
}
if ($which == 0) {
$options['class'] = 'first';
} elseif ($which == $crumb_count - 1) {
$options['class'] = 'last';
}
$result .= $this->tag(
'li',
$element_content,
$options
);
}
return $this->tag(
'ul',
$result,
$list_options
);
} else {
return null;
}
}
/**
* Creates a formatted IMG element. If `$options['url']` is provided, an image link will be
* generated with the link pointed at `$options['url']`. This method will set an empty
@@ -1273,4 +1273,40 @@ function testPara() {
$result = $this->Html->para('class-name', '<text>', array('escape' => true));
$this->assertTags($result, array('p' => array('class' => 'class-name'), '&lt;text&gt;', '/p'));
}
/**
* testCrumbList method
*
* @access public
*
* @return void
*/
function testCrumbList() {
$this->Html->addCrumb('Home', '/', array('class' => 'home'));
$this->Html->addCrumb('Some page', '/some_page');
$this->Html->addCrumb('Another page');
$result = $this->Html->getCrumbList(
array('class' => 'breadcrumbs')
);
$this->assertTags(
$result,
array(
array('ul' => array('class' => 'breadcrumbs')),
array('li' => array('class' => 'first')),
array('a' => array('class' => 'home', 'href' => '/')),
'Home',
'/a',
'/li',
'<li',
array('a' => array('href' => '/some_page')),
'Some page',
'/a',
'/li',
array('li' => array('class' => 'last')),
'Another page',
'/li',
'/ul'
)
);
}
}

0 comments on commit 68a9c9c

Please sign in to comment.
You can’t perform that action at this time.