/** * Converts menu config into something KNP menus expects * * @param $items * @param int $depth * @param int $defaultPriority */ public function createMenuStructure(&$items, $depth = 0, $defaultPriority = 9999) { foreach ($items as $k => &$i) { if (!is_array($i) || empty($i)) { continue; } if (isset($i['bundle'])) { // Category shortcut $bundleName = $i['bundle']; $i = ['access' => $bundleName . ':categories:view', 'route' => 'mautic_category_index', 'id' => 'mautic_' . $bundleName . 'category_index', 'routeParameters' => ['bundle' => $bundleName]]; } // Check to see if menu is restricted if (isset($i['access'])) { if ($i['access'] == 'admin') { if (!$this->user->isAdmin()) { unset($items[$k]); continue; } } elseif (!$this->security->isGranted($i['access'], 'MATCH_ONE')) { unset($items[$k]); continue; } } if (isset($i['checks'])) { $passChecks = true; foreach ($i['checks'] as $checkGroup => $checks) { foreach ($checks as $name => $value) { if ($checkGroup == 'parameters') { if ($this->getParameter($name) != $value) { $passChecks = false; break; } } elseif ($checkGroup == 'request') { if ($this->request->get($name) != $value) { $passChecks = false; break; } } } } if (!$passChecks) { unset($items[$k]); continue; } } //Set ID to route name if (!isset($i['id'])) { if (!empty($i['route'])) { $i['id'] = $i['route']; } else { $i['id'] = 'menu-item-' . uniqid(); } } //Set link attributes if (!isset($i['linkAttributes'])) { $i['linkAttributes'] = ['data-menu-link' => $i['id'], 'id' => $i['id']]; } elseif (!isset($i['linkAttributes']['id'])) { $i['linkAttributes']['id'] = $i['id']; $i['linkAttributes']['data-menu-link'] = $i['id']; } elseif (!isset($i['linkAttributes']['data-menu-link'])) { $i['linkAttributes']['data-menu-link'] = $i['id']; } $i['extras'] = []; $i['extras']['depth'] = $depth; // Note a divider if (!empty($i['divider'])) { $i['extras']['divider'] = true; } // Note a header if (!empty($i['header'])) { $i['extras']['header'] = $i['header']; } //Set the icon class for the menu item if (!empty($i['iconClass'])) { $i['extras']['iconClass'] = $i['iconClass']; } //Set the actual route name so that it's available to the menu template if (isset($i['route'])) { $i['extras']['routeName'] = $i['route']; } //Repeat for sub items if (isset($i['children'])) { $this->createMenuStructure($i['children'], $depth + 1, $defaultPriority); } // Determine if this item needs to be listed in a bundle outside it's own if (isset($i['parent'])) { if (!isset($this->orphans[$i['parent']])) { $this->orphans[$i['parent']] = []; } $this->orphans[$i['parent']][$k] = $i; unset($items[$k]); // Don't set a default priority here as it'll assume that of it's parent } elseif (!isset($i['priority'])) { // Ensure a priority for non-orphans $i['priority'] = $defaultPriority; } } }
/** * {@inheritDoc} */ public function isAdmin() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'isAdmin', array()); return parent::isAdmin(); }