1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Breadcrumbs Navigation view helper styled for Bootstrap 3. |
5
|
|
|
* |
6
|
|
|
* @author Leandro Silva <[email protected]> |
7
|
|
|
* |
8
|
|
|
* @category LosUi |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/Lansoweb/LosUi/blob/master/LICENSE MIT License |
11
|
|
|
* |
12
|
|
|
* @link http://github.com/LansoWeb/LosUi |
13
|
|
|
* @link http://getbootstrap.com/components/#breadcrumbs |
14
|
|
|
*/ |
15
|
|
|
namespace LosUi\View\Helper\Navigation; |
16
|
|
|
|
17
|
|
|
use Zend\Navigation\Page\AbstractPage; |
18
|
|
|
use Zend\View\Helper\Navigation\Breadcrumbs as ZendBreadcrumbs; |
19
|
|
|
use Zend\Navigation\Page\Uri; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Breadcrumbs Navigation view helper styled for Bootstrap 3. |
23
|
|
|
* |
24
|
|
|
* @author Leandro Silva <[email protected]> |
25
|
|
|
* |
26
|
|
|
* @category LosUi |
27
|
|
|
* |
28
|
|
|
* @license https://github.com/Lansoweb/LosUi/blob/master/LICENSE MIT License |
29
|
|
|
* |
30
|
|
|
* @link http://github.com/LansoWeb/LosUi |
31
|
|
|
* @link http://getbootstrap.com/components/#breadcrumbs |
32
|
|
|
* @codeCoverageIgnore |
33
|
|
|
*/ |
34
|
|
|
class Breadcrumbs extends ZendBreadcrumbs |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Setting default minDepth to 0. |
38
|
|
|
* |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
protected $minDepth = 0; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Bootstrap breadcrumbs already sets a separator. |
45
|
|
|
*/ |
46
|
|
|
protected $separator = ''; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* (non-PHPdoc). |
50
|
|
|
* |
51
|
|
|
* @see \Zend\View\Helper\Navigation\AbstractHelper::htmlify() |
52
|
|
|
* @param AbstractPage $page |
53
|
|
|
* @param bool $hasParent |
54
|
|
|
* @return string |
55
|
|
|
*/ |
56
|
|
|
public function htmlify(AbstractPage $page, $hasParent = false) |
57
|
|
|
{ |
58
|
|
|
$html = '<li'; |
59
|
|
|
if (! $hasParent) { |
60
|
|
|
$html .= ' class="active"'; |
61
|
|
|
} |
62
|
|
|
$html .= '>'; |
63
|
|
|
|
64
|
|
|
$label = $page->getLabel(); |
65
|
|
|
if (null !== ($translator = $this->getTranslator())) { |
66
|
|
|
$label = $translator->translate($label, $this->getTranslatorTextDomain()); |
67
|
|
|
} |
68
|
|
|
$escaper = $this->view->plugin('escapeHtml'); |
69
|
|
|
$label = $escaper($label); |
70
|
|
|
|
71
|
|
|
if ($page->getHref() && ($hasParent || (! $hasParent && $this->getLinkLast())) && |
72
|
|
|
(! ($page instanceof Uri) || $page->getUri() != '#')) { |
73
|
|
|
$anchorAttribs = $this->htmlAttribs(['href' => $page->getHref()]); |
74
|
|
|
$html .= '<a'.$anchorAttribs.'>'.$label.'</a>'; |
75
|
|
|
} else { |
76
|
|
|
$html .= $label; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$html .= '</li>'; |
80
|
|
|
|
81
|
|
|
return $html; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* (non-PHPdoc). |
86
|
|
|
* |
87
|
|
|
* @see \Zend\View\Helper\Navigation\Breadcrumbs::renderStraight() |
88
|
|
|
* @param null $container |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function renderStraight($container = null) |
92
|
|
|
{ |
93
|
|
|
$this->parseContainer($container); |
94
|
|
|
if (null === $container) { |
95
|
|
|
$container = $this->getContainer(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if (! $active = $this->findActive($container)) { |
|
|
|
|
99
|
|
|
return ''; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
$active = $active['page']; |
103
|
|
|
$html = $this->htmlify($active); |
104
|
|
|
|
105
|
|
|
while ($parent = $active->getParent()) { |
106
|
|
|
if ($parent instanceof AbstractPage) { |
107
|
|
|
$html = $this->htmlify($parent, true).$html; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if ($parent === $container) { |
111
|
|
|
break; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$active = $parent; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
return strlen($html) ? '<ol class="breadcrumb">'.$this->getIndent().$html.'</ol>' : ''; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.