/** * Creates a URL according to the given route and parameters. * @param UrlManager $manager the URL manager * @param string $route the route. It should not have slashes at the beginning or the end. * @param array $params the parameters * @return string|boolean the created URL, or false if this rule cannot be used for creating this URL. */ public function createUrl($manager, $route, $params) { $language = \Yii::$app->language; $menuMap = $this->menuManager->getMenuMap($language); if ($path = $menuMap->getMenuPathByRoute(MenuItem::toRoute($route, $params))) { return $path; } $requestInfo = new MenuRequestInfo(['menuMap' => $menuMap, 'requestRoute' => $route, 'requestParams' => $params]); foreach ($this->_createUrlRules as $rule) { if ($result = $rule->process($requestInfo, $this)) { return $result; } } return false; }
/** * Renders the content of a menu item. * Note that the container and the sub-menus are not rendered here. * @param array $item the menu item to be rendered. Please refer to [[items]] to see what data might be in the item. * @return string the rendering result */ protected function renderItem($item) { $routers = ''; $header = ''; if (isset($item['label'])) { $template = ArrayHelper::getValue($item, 'headerTemplate', $this->headerTemplate); $header = strtr($template, ['{icon}' => $item['icon'], '{label}' => $item['label']]); } foreach ($item['items'] as $router) { $template = ArrayHelper::getValue($router, 'template', $this->routerTemplate); $routerContent = strtr($template, ['{icon}' => $router['icon'], '{link}' => isset($router['url']) ? Html::a($router['label'], $router['url']) : Html::a($router['label'], '#', ['onclick' => ModalIFrame::postDataJs(['route' => MenuItem::toRoute($router['route']), 'link' => Yii::$app->urlManager->createUrl($router['route'])])])]); $routerOptions = array_merge($this->routerOptions, $router['options']); $routers .= Html::tag(ArrayHelper::remove($routerOptions, 'tag', 'div'), $routerContent, $routerOptions); } $template = ArrayHelper::getValue($item, 'template', $this->itemTemplate); return strtr($template, ['{header}' => $header, '{routers}' => $routers]); }