Passed
Push — master ( a81262...3fd1e4 )
by Mihail
14:43
created

LanguageSwitcher::display()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 24
rs 8.9714
cc 3
eloc 15
nc 3
nop 0
1
<?php
2
3
namespace Widgets\Basic;
4
5
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\Widget;
8
use Ffcms\Core\Helper\HTML\Listing;
9
10
class LanguageSwitcher extends Widget
11
{
12
    private $multiLangEnabled = false;
13
14
    public $css = ['class' => 'list-inline'];
15
16
    public function init()
17
    {
18
        $this->multiLangEnabled = App::$Properties->get('multiLanguage', 'default', true);
19
20
        if ($this->multiLangEnabled === true) {
21
            App::$Alias->setCustomLibrary('css', '/vendor/phpffcms/language-flags/flags.css');
22
        }
23
    }
24
25
    public function display()
26
    {
27
        // prevent loading on disabled multi-language property
28
        if ($this->multiLangEnabled !== true) {
29
            return null;
30
        }
31
32
        $items = [];
33
        foreach (App::$Translate->getAvailableLangs() as $lang) {
34
            $items[] = [
35
                'type' => 'link',
36
                'link' => App::$Alias->scriptUrl . '/' . $lang . App::$Request->getPathInfo(),
37
                'text' => '<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="flag flag-'.$lang.'" />',
38
                'html' => true,
39
                '!secure' => true
40
            ];
41
        }
42
43
        return Listing::display([
44
            'type' => 'ul',
45
            'property' => $this->css,
46
            'items' => $items
47
        ]);
48
    }
49
}