From 16280df6d10404895ffe285bc8a7e2c57fbd6fe2 Mon Sep 17 00:00:00 2001 From: dozer111 Date: Thu, 14 Jun 2018 10:32:48 +0300 Subject: [PATCH] Линк услуги не должен ссылатся сам на себя --- frontend/views/layouts/main.php | 3 +++ frontend/widgets/Nav.php | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 0 deletions(-) diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index a88c6dd..8f7dd49 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -211,6 +211,8 @@ { $test[$key]['label']=$item['label']; $test[$key]['options'] = [ 'class' => 'active' ]; + $test[$key]['url']= false; + } elseif( \Yii::$app->request->url=='/' && $item['label']==\Yii::t('app', 'Prices')) @@ -230,6 +232,7 @@ ?> + $test, diff --git a/frontend/widgets/Nav.php b/frontend/widgets/Nav.php index 6e3c30a..284795f 100644 --- a/frontend/widgets/Nav.php +++ b/frontend/widgets/Nav.php @@ -9,20 +9,94 @@ namespace frontend\widgets; use yii\helpers\Html; + use yii\helpers\ArrayHelper; + class Nav extends \yii\bootstrap\Nav { + + # метод почти полностью повторяет родительский, + # различия работы см.в return + public function renderItem($item) + { + if (is_string($item)) { + return $item; + } + if (!isset($item['label'])) { + throw new InvalidConfigException("The 'label' option is required."); + } + $encodeLabel = isset($item['encode']) ? $item['encode'] : $this->encodeLabels; + $label = $encodeLabel ? Html::encode($item['label']) : $item['label']; + $options = ArrayHelper::getValue($item, 'options', []); + $items = ArrayHelper::getValue($item, 'items'); + $url = ArrayHelper::getValue($item, 'url', '#'); + + $linkOptions = ArrayHelper::getValue($item, 'linkOptions', []); + + if (isset($item['active'])) { + $active = ArrayHelper::remove($item, 'active', false); + } else { + $active = $this->isItemActive($item); + } + + if (empty($items)) { + $items = ''; + } else { + $linkOptions['data-toggle'] = 'dropdown'; + Html::addCssClass($options, ['widget' => 'dropdown']); + Html::addCssClass($linkOptions, ['widget' => 'dropdown-toggle']); + if ($this->dropDownCaret !== '') { + $label .= ' ' . $this->dropDownCaret; + } + if (is_array($items)) { + $items = $this->isChildActive($items, $active); + $items = $this->renderDropdown($items, $item); + } + } + + if ($active) { + Html::addCssClass($options, 'active'); + } + + return ($url!=='')? + Html::tag('li', Html::a($label, $url, $linkOptions) . $items, $options) + : Html::tag('li', Html::a($label, null, $linkOptions) . $items, $options) + ; + } + + + + + + + public function init() { + + foreach ($this->items as &$item) + { + if($item['url']===false)$item['url']=''; + } + + if ($this->route === null && \Yii::$app->controller !== null) { $this->route = \Yii::$app->controller->getRoute(); + } + if ($this->params === null) { $this->params = \Yii::$app->request->getQueryParams(); + } + if ($this->dropDownCaret === null) { $this->dropDownCaret = ''; + } + + + Html::addCssClass($this->options, []); + } } \ No newline at end of file -- libgit2 0.21.4