Skip to content

Commit

Permalink
Merge pull request #511 from tigrang/crumb-list-opt
Browse files Browse the repository at this point in the history
Moving duplicate logic to a new method
  • Loading branch information
markstory committed Feb 22, 2012
2 parents cee8f2c + 95ba5f4 commit e5205a8
Showing 1 changed file with 26 additions and 28 deletions.
54 changes: 26 additions & 28 deletions lib/Cake/View/Helper/HtmlHelper.php
Expand Up @@ -684,21 +684,8 @@ public function style($data, $oneline = true) {
public function getCrumbs($separator = '»', $startText = false) {
if (!empty($this->_crumbs)) {
$out = array();
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']);

$out[] = $this->link($text, $url, $startText);
}

foreach ($this->_crumbs as $crumb) {
$crumbs = $this->_prepareCrumbs($startText);
foreach ($crumbs as $crumb) {
if (!empty($crumb[1])) {
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
} else {
Expand Down Expand Up @@ -727,19 +714,7 @@ public function getCrumbs($separator = '»', $startText = false) {
public function getCrumbList($options = array(), $startText = false) {
if (!empty($this->_crumbs)) {
$result = '';
$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));
}
$crumbs = $this->_prepareCrumbs($startText);
$crumbCount = count($crumbs);
$ulOptions = $options;
foreach ($crumbs as $which => $crumb) {
Expand All @@ -762,6 +737,29 @@ public function getCrumbList($options = array(), $startText = false) {
}
}

/**
* Prepends startText to crumbs array if set
*
* @param $startText
* @return array Crumb list including startText (if provided)
*/
protected function _prepareCrumbs($startText) {
$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));
}
return $crumbs;
}

/**
* Creates a formatted IMG element.
*
Expand Down

0 comments on commit e5205a8

Please sign in to comment.