-
Notifications
You must be signed in to change notification settings - Fork 5
/
Flag.php
57 lines (45 loc) · 1.21 KB
/
Flag.php
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* @author Harry Tang <harry@powerkernel.com>
* @link https://powerkernel.com
* @copyright Copyright (c) 2016 Power Kernel
*/
namespace powerkernel\flagiconcss;
use yii\base\Widget;
use yii\bootstrap\Html;
/**
* Class Flag
* @package powerkernel\flagiconcss
*/
class Flag extends Widget
{
public $tag = 'span';
public $country; // the ISO 3166-1-alpha-2 code of a country,
public $squared = false; // set to true if you want to have a squared version flag
public $options = [];
/**
* @inheritdoc
*/
public function run()
{
parent::run(); // TODO: Change the autogenerated stub
if (!empty($this->country)) {
$class = 'flag-icon flag-icon-' . $this->country;
Html::addCssClass($this->options, $class);
if ($this->squared) {
Html::addCssClass($this->options, 'flag-icon-squared');
}
$this->register();
echo Html::beginTag($this->tag, $this->options);
echo Html::endTag($this->tag);
}
}
/**
* register assets
*/
protected function register()
{
$view = $this->getView();
FlagiconcssAsset::register($view);
}
}