Commit 5385a565f3a11169fd501e051eca16d7eb50749a
1 parent
50715b7a
lang link widget
Showing
5 changed files
with
79 additions
and
21 deletions
Show diff stats
console/migrations/m180830_091730_alter_table_language.php
0 → 100644
1 | +<?php | |
2 | + | |
3 | +use yii\db\Migration; | |
4 | + | |
5 | +/** | |
6 | + * Class m180830_091730_alter_table_language | |
7 | + */ | |
8 | +class m180830_091730_alter_table_language extends Migration | |
9 | +{ | |
10 | + /** | |
11 | + * {@inheritdoc} | |
12 | + */ | |
13 | + public function safeUp() | |
14 | + { | |
15 | + $this->addColumn('language', 'short', $this->string()); | |
16 | + } | |
17 | + | |
18 | + /** | |
19 | + * {@inheritdoc} | |
20 | + */ | |
21 | + public function safeDown() | |
22 | + { | |
23 | + $this->dropColumn('language', 'short'); | |
24 | + } | |
25 | + | |
26 | + /* | |
27 | + // Use up()/down() to run migration code without a transaction. | |
28 | + public function up() | |
29 | + { | |
30 | + | |
31 | + } | |
32 | + | |
33 | + public function down() | |
34 | + { | |
35 | + echo "m180830_091730_alter_table_language cannot be reverted.\n"; | |
36 | + | |
37 | + return false; | |
38 | + } | |
39 | + */ | |
40 | +} | ... | ... |
frontend/views/layouts/main.php
... | ... | @@ -101,16 +101,7 @@ |
101 | 101 | <header id="header_" class="section-box-header"> |
102 | 102 | <section class="first-menu hidden-xs"> |
103 | 103 | <div class="container"> |
104 | - <div class="row"> | |
105 | - <div class="col-xs-12"> | |
106 | - <ul> | |
107 | - <li><a class="active">Українська</a></li> | |
108 | - <li><a href="#">English</a></li> | |
109 | - <li><a href="#">Française</a></li> | |
110 | - <li><a href="#">Русский</a></li> | |
111 | - </ul> | |
112 | - </div> | |
113 | - </div> | |
104 | + <?=\frontend\widgets\LangLinks::widget()?> | |
114 | 105 | </div> |
115 | 106 | </section> |
116 | 107 | <section class="logos-titles"> |
... | ... | @@ -165,12 +156,7 @@ |
165 | 156 | |
166 | 157 | <div class="mobile-menu-hidden" style="display: none;"> |
167 | 158 | <div class="close-lang-mob"> |
168 | - <ul class="menu-lang"> | |
169 | - <li><a class="active">Укр</a></li> | |
170 | - <li><a href="#">Eng</a></li> | |
171 | - <li><a href="#">Fr</a></li> | |
172 | - <li><a href="#">Руc</a></li> | |
173 | - </ul> | |
159 | + <?=\frontend\widgets\LangLinks::widget(['mobile' => true])?> | |
174 | 160 | <div class="close-mobile-menu"></div> |
175 | 161 | </div> |
176 | 162 | ... | ... |
frontend/widgets/LangLinks.php
... | ... | @@ -8,17 +8,19 @@ |
8 | 8 | |
9 | 9 | namespace frontend\widgets; |
10 | 10 | |
11 | - use artbox\core\helpers\Html; | |
11 | + use yii\helpers\Html; | |
12 | 12 | use artbox\core\models\Language; |
13 | 13 | use yii\jui\Widget; |
14 | 14 | |
15 | 15 | class LangLinks extends Widget |
16 | 16 | { |
17 | 17 | public $links; |
18 | + | |
19 | + public $mobile = false; | |
18 | 20 | public function init() |
19 | 21 | { |
20 | 22 | /** |
21 | - * @var \artbox\core\components\LangComponent $langComponent ; | |
23 | + * @var \frontend\components\LangComponent $langComponent ; | |
22 | 24 | */ |
23 | 25 | $langComponent = \Yii::$app->get('langLinks'); |
24 | 26 | |
... | ... | @@ -32,12 +34,15 @@ |
32 | 34 | |
33 | 35 | foreach ($langs as $key => $item) { |
34 | 36 | if ($item->id == Language::getCurrent()->id) { |
35 | - $items[ $key ] = $item->url; | |
37 | + $items[ $key ] = Html::tag('li', Html::a(($this->mobile ? $item->short : $item->name), '', ['class' => 'active'])); | |
36 | 38 | } else { |
37 | - $items[ $key ] = Html::a($item->url, $this->links[ $key ]); | |
39 | + $items[ $key ] = Html::tag('li', Html::a(($this->mobile ? $item->short : $item->name), $this->links[ $key ])); | |
38 | 40 | } |
41 | + | |
42 | + } | |
43 | + if ($this->mobile){ | |
44 | + return $this->render('links_mobile', [ 'links' => $items ]); | |
39 | 45 | } |
40 | - | |
41 | 46 | return $this->render('links', [ 'links' => $items ]); |
42 | 47 | } |
43 | 48 | } |
44 | 49 | \ No newline at end of file | ... | ... |