mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-03-01 23:29:45 +00:00
Merge pull request #511 from tigrang/crumb-list-opt
Moving duplicate logic to a new method
This commit is contained in:
commit
e5205a8dcc
1 changed files with 26 additions and 28 deletions
|
@ -684,21 +684,8 @@ class HtmlHelper extends AppHelper {
|
||||||
public function getCrumbs($separator = '»', $startText = false) {
|
public function getCrumbs($separator = '»', $startText = false) {
|
||||||
if (!empty($this->_crumbs)) {
|
if (!empty($this->_crumbs)) {
|
||||||
$out = array();
|
$out = array();
|
||||||
if ($startText) {
|
$crumbs = $this->_prepareCrumbs($startText);
|
||||||
if (!is_array($startText)) {
|
foreach ($crumbs as $crumb) {
|
||||||
$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) {
|
|
||||||
if (!empty($crumb[1])) {
|
if (!empty($crumb[1])) {
|
||||||
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
$out[] = $this->link($crumb[0], $crumb[1], $crumb[2]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -727,19 +714,7 @@ class HtmlHelper extends AppHelper {
|
||||||
public function getCrumbList($options = array(), $startText = false) {
|
public function getCrumbList($options = array(), $startText = false) {
|
||||||
if (!empty($this->_crumbs)) {
|
if (!empty($this->_crumbs)) {
|
||||||
$result = '';
|
$result = '';
|
||||||
$crumbs = $this->_crumbs;
|
$crumbs = $this->_prepareCrumbs($startText);
|
||||||
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);
|
$crumbCount = count($crumbs);
|
||||||
$ulOptions = $options;
|
$ulOptions = $options;
|
||||||
foreach ($crumbs as $which => $crumb) {
|
foreach ($crumbs as $which => $crumb) {
|
||||||
|
@ -762,6 +737,29 @@ class HtmlHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
* Creates a formatted IMG element.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue