58 parent::__construct($context,
$data);
59 $this->nodeFactory = $nodeFactory;
60 $this->treeFactory = $treeFactory;
71 return parent::getCacheLifetime() ?: 3600;
82 public function getHtml($outermostClass =
'', $childrenWrapClass =
'', $limit = 0)
84 $this->_eventManager->dispatch(
85 'page_block_html_topmenu_gethtml_before',
89 $this->
getMenu()->setOutermostClass($outermostClass);
90 $this->
getMenu()->setChildrenWrapClass($childrenWrapClass);
92 $html = $this->_getHtml($this->
getMenu(), $childrenWrapClass, $limit);
94 $transportObject = new \Magento\Framework\DataObject([
'html' => $html]);
95 $this->_eventManager->dispatch(
96 'page_block_html_topmenu_gethtml_after',
97 [
'menu' => $this->
getMenu(),
'transportObject' => $transportObject]
99 $html = $transportObject->getHtml();
109 protected function _countItems(
$items)
114 if (
$item->hasChildren()) {
115 $total += $this->_countItems(
$item->getChildren());
132 $total = $this->_countItems(
$items);
133 if ($total <= $limit) {
137 $result[] = [
'total' => $total,
'max' => (int)ceil($total / ceil($total / $limit))];
143 $place = $this->_countItems(
$item->getChildren()) + 1;
146 if ($place >= $limit) {
147 $colbrake = !$firstCol;
150 $colbrake = !$firstCol;
156 $result[] = [
'place' => $place,
'colbrake' => $colbrake];
173 protected function _addSubMenu($child, $childLevel, $childrenWrapClass, $limit)
176 if (!$child->hasChildren()) {
181 if ($childLevel == 0 && $limit) {
182 $colStops = $this->
_columnBrake($child->getChildren(), $limit);
185 $html .=
'<ul class="level' . $childLevel .
' ' . $childrenWrapClass .
'">';
186 $html .= $this->_getHtml($child, $childrenWrapClass, $limit, $colStops);
204 protected function _getHtml(
208 array $colBrakes = []
213 $parentLevel = $menuTree->getLevel();
214 $childLevel = $parentLevel ===
null ? 0 : $parentLevel + 1;
220 $parentPositionClass = $menuTree->getPositionClass();
221 $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass .
'-' :
'nav-';
225 if ($childLevel === 0 && $child->getData(
'is_parent_active') ===
false) {
228 $child->setLevel($childLevel);
229 $child->setIsFirst($counter == 1);
230 $child->setIsLast($counter == $childrenCount);
231 $child->setPositionClass($itemPositionClassPrefix . $counter);
233 $outermostClassCode =
'';
234 $outermostClass = $menuTree->getOutermostClass();
236 if ($childLevel == 0 && $outermostClass) {
237 $outermostClassCode =
' class="' . $outermostClass .
'" ';
238 $currentClass = $child->getClass();
240 if (empty($currentClass)) {
241 $child->setClass($outermostClass);
243 $child->setClass($currentClass .
' ' . $outermostClass);
247 if (is_array($colBrakes) && count($colBrakes) && $colBrakes[$counter][
'colbrake']) {
248 $html .=
'</ul></li><li class="column"><ul>';
252 $html .=
'<a href="' . $child->getUrl() .
'" ' . $outermostClassCode .
'><span>' . $this->
escapeHtml(
264 if (is_array($colBrakes) && count($colBrakes) && $limit) {
265 $html =
'<li class="column"><ul>' . $html .
'</ul></li>';
281 foreach (
$attributes as $attributeName => $attributeValue) {
282 $html .=
' ' . $attributeName .
'="' . str_replace(
'"',
'\"', $attributeValue) .
'"';
296 return [
'class' => implode(
' ', $menuItemClasses)];
309 $classes[] =
'level' .
$item->getLevel();
310 $classes[] =
$item->getPositionClass();
312 if (
$item->getIsCategory()) {
313 $classes[] =
'category-item';
316 if (
$item->getIsFirst()) {
317 $classes[] =
'first';
320 if (
$item->getIsActive()) {
321 $classes[] =
'active';
323 $classes[] =
'has-active';
326 if (
$item->getIsLast()) {
330 if (
$item->getClass()) {
331 $classes[] =
$item->getClass();
334 if (
$item->hasChildren()) {
335 $classes[] =
'parent';
349 if (!in_array($identity, $this->identities)) {
350 $this->identities[] = $identity;
372 $keyInfo = parent::getCacheKeyInfo();
373 $keyInfo[] = $this->
getUrl(
'*/*/*', [
'_current' =>
true,
'_query' =>
'']);
385 return array_merge(parent::getCacheTags(), $this->
getIdentities());
400 $this->_menu = $this->nodeFactory->create(
404 'tree' => $this->treeFactory->create()
elseif(isset( $params[ 'redirect_parent']))
escapeHtml($data, $allowedTags=null)
getUrl($route='', $params=[])