Blame view

frontend/widgets/Nav.php 2.9 KB
c7048abc   Anastasia   - nav widget with...
1
2
3
4
5
6
7
8
9
10
11
  <?php
      /**
       * Created by PhpStorm.
       * User: stes
       * Date: 25.05.18
       * Time: 17:55
       */
      
      namespace frontend\widgets;
      
      use yii\helpers\Html;
16280df6   alex   Линк услуги не до...
12
13
      use yii\helpers\ArrayHelper;
  
c7048abc   Anastasia   - nav widget with...
14
15
16
  
      class Nav extends \yii\bootstrap\Nav
      {
16280df6   alex   Линк услуги не до...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  
          # метод почти полностью повторяет родительский,
          # различия работы см.в 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)
                  ;
          }
  
  
  
  
  
  
  
c7048abc   Anastasia   - nav widget with...
73
74
          public function init()
          {
16280df6   alex   Линк услуги не до...
75
76
77
78
79
80
81
  
              foreach ($this->items as &$item)
              {
                  if($item['url']===false)$item['url']='';
              }
  
  
c7048abc   Anastasia   - nav widget with...
82
83
              if ($this->route === null && \Yii::$app->controller !== null) {
                  $this->route = \Yii::$app->controller->getRoute();
16280df6   alex   Линк услуги не до...
84
  
c7048abc   Anastasia   - nav widget with...
85
              }
16280df6   alex   Линк услуги не до...
86
  
c7048abc   Anastasia   - nav widget with...
87
88
              if ($this->params === null) {
                  $this->params = \Yii::$app->request->getQueryParams();
16280df6   alex   Линк услуги не до...
89
  
c7048abc   Anastasia   - nav widget with...
90
              }
16280df6   alex   Линк услуги не до...
91
  
c7048abc   Anastasia   - nav widget with...
92
93
              if ($this->dropDownCaret === null) {
                  $this->dropDownCaret = '<span class="caret"></span>';
16280df6   alex   Линк услуги не до...
94
  
c7048abc   Anastasia   - nav widget with...
95
              }
16280df6   alex   Линк услуги не до...
96
97
98
  
  
  
c7048abc   Anastasia   - nav widget with...
99
              Html::addCssClass($this->options, []);
16280df6   alex   Линк услуги не до...
100
  
c7048abc   Anastasia   - nav widget with...
101
102
          }
      }