Blame view

frontend/widgets/LangLinks.php 1.1 KB
bc9815fa   Anastasia   layout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
  <?php
      /**
       * Created by PhpStorm.
       * User: stes
       * Date: 03.08.18
       * Time: 14:34
       */
      
      namespace frontend\widgets;
      
      use artbox\core\helpers\Html;
      use artbox\core\models\Language;
      use yii\jui\Widget;
      
      class LangLinks extends Widget
      {
          public $links;
          public function init()
          {
              /**
               * @var \artbox\core\components\LangComponent $langComponent ;
               */
              $langComponent = \Yii::$app->get('langLinks');
              
              $this->links = $langComponent->getLinks();
          }
          
          public function run()
          {
              $items = [];
              $langs = Language::getActive();
              
              foreach ($langs as $key => $item) {
                  if ($item->id == Language::getCurrent()->id) {
                      $items[ $key ] = $item->url;
                  } else {
                      $items[ $key ] = Html::a($item->url, $this->links[ $key ]);
                  }
              }
              
              return $this->render('links', [ 'links' => $items ]);
          }
      }