1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the core-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Twig\Extension\Plugin; |
13
|
|
|
|
14
|
|
|
use Twig_Environment; |
15
|
|
|
use Twig_SimpleFilter; |
16
|
|
|
use Twig_SimpleFunction; |
17
|
|
|
use WBW\Bundle\CoreBundle\Renderer\IconRendererInterface; |
18
|
|
|
use WBW\Library\Core\Argument\ArrayHelper; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Font Awesome Twig extension. |
22
|
|
|
* |
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
24
|
|
|
* @package WBW\Bundle\CoreBundle\Twig\Extension\Plugin |
25
|
|
|
*/ |
26
|
|
|
class FontAwesomeTwigExtension extends AbstractFontAwesomeTwigExtension implements IconRendererInterface { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Service name. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
const SERVICE_NAME = "webeweb.core.twig.extension.plugin.font_awesome"; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Constructor. |
37
|
|
|
* |
38
|
|
|
* @param Twig_Environment $twigEnvironment The wig environment. |
39
|
|
|
*/ |
40
|
|
|
public function __construct(Twig_Environment $twigEnvironment) { |
41
|
|
|
parent::__construct($twigEnvironment); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Displays a Font Awesome icon. |
46
|
|
|
* |
47
|
|
|
* @param array $args The arguments. |
48
|
|
|
* @return string Returns the Font Awesome icon. |
49
|
|
|
*/ |
50
|
|
|
public function fontAwesomeIconFunction(array $args = []) { |
51
|
|
|
return $this->fontAwesomeIcon(ArrayHelper::get($args, "font"), ArrayHelper::get($args, "name", "home"), ArrayHelper::get($args, "size"), ArrayHelper::get($args, "fixedWidth", false), ArrayHelper::get($args, "bordered", false), ArrayHelper::get($args, "pull"), ArrayHelper::get($args, "animated"), ArrayHelper::get($args, "style")); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Displays a Font Awesome list. |
56
|
|
|
* |
57
|
|
|
* @param array|string $items The items. |
58
|
|
|
* @return string Returns the Font Awesome list. |
59
|
|
|
*/ |
60
|
|
|
public function fontAwesomeListFilter($items) { |
61
|
|
|
return $this->fontAwesomeList($items); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Displays a Font Awesome list icon. |
66
|
|
|
* |
67
|
|
|
* @param string $icon The icon. |
68
|
|
|
* @param string $content The content. |
69
|
|
|
* @return string Returns the Font Awesome list icon. |
70
|
|
|
*/ |
71
|
|
|
public function fontAwesomeListIconFilter($icon, $content) { |
72
|
|
|
return $this->fontAwesomeListIcon($icon, $content); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Get the Twig filters. |
77
|
|
|
* |
78
|
|
|
* @return Twig_SimpleFilter[] Returns the Twig filters. |
79
|
|
|
*/ |
80
|
|
|
public function getFilters() { |
81
|
|
|
return [ |
82
|
|
|
new Twig_SimpleFilter("fontAwesomeList", [$this, "fontAwesomeListFilter"], ["is_safe" => ["html"]]), |
83
|
|
|
new Twig_SimpleFilter("fontAwesomeListIcon", [$this, "fontAwesomeListIconFilter"], ["is_safe" => ["html"]]), |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get the Twig functions. |
89
|
|
|
* |
90
|
|
|
* @return array Returns the Twig functions. |
91
|
|
|
*/ |
92
|
|
|
public function getFunctions() { |
93
|
|
|
return [ |
94
|
|
|
new Twig_SimpleFunction("fontAwesomeIcon", [$this, "fontAwesomeIconFunction"], ["is_safe" => ["html"]]), |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* {@inheritdoc} |
100
|
|
|
*/ |
101
|
|
|
public function renderIcon($name, $style) { |
102
|
|
|
return $this->fontAwesomeIconFunction(["name" => $name, "style" => $style]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
} |
106
|
|
|
|