|
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_SimpleFilter; |
|
15
|
|
|
use Twig_SimpleFunction; |
|
16
|
|
|
use WBW\Bundle\CoreBundle\Icon\IconFactory; |
|
17
|
|
|
use WBW\Bundle\CoreBundle\Renderer\IconRendererInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Font Awesome Twig extension. |
|
21
|
|
|
* |
|
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
23
|
|
|
* @package WBW\Bundle\CoreBundle\Twig\Extension\Plugin |
|
24
|
|
|
*/ |
|
25
|
|
|
class FontAwesomeTwigExtension extends AbstractFontAwesomeTwigExtension implements IconRendererInterface { |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Service name. |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
const SERVICE_NAME = "webeweb.core.twig.extension.plugin.font_awesome"; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Displays a Font Awesome icon. |
|
36
|
|
|
* |
|
37
|
|
|
* @param array $args The arguments. |
|
38
|
|
|
* @return string Returns the Font Awesome icon. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function fontAwesomeIconFunction(array $args = []) { |
|
41
|
|
|
return $this->fontAwesomeIcon(IconFactory::parseFontAwesomeIcon($args)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Displays a Font Awesome list. |
|
46
|
|
|
* |
|
47
|
|
|
* @param array|string $items The items. |
|
48
|
|
|
* @return string Returns the Font Awesome list. |
|
49
|
|
|
*/ |
|
50
|
|
|
public function fontAwesomeListFilter($items) { |
|
51
|
|
|
return $this->fontAwesomeList($items); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Displays a Font Awesome list icon. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $icon The icon. |
|
58
|
|
|
* @param string $content The content. |
|
59
|
|
|
* @return string Returns the Font Awesome list icon. |
|
60
|
|
|
*/ |
|
61
|
|
|
public function fontAwesomeListIconFilter($icon, $content) { |
|
62
|
|
|
return $this->fontAwesomeListIcon($icon, $content); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Get the Twig filters. |
|
67
|
|
|
* |
|
68
|
|
|
* @return Twig_SimpleFilter[] Returns the Twig filters. |
|
69
|
|
|
*/ |
|
70
|
|
|
public function getFilters() { |
|
71
|
|
|
return [ |
|
72
|
|
|
new Twig_SimpleFilter("fontAwesomeList", [$this, "fontAwesomeListFilter"], ["is_safe" => ["html"]]), |
|
73
|
|
|
new Twig_SimpleFilter("faList", [$this, "fontAwesomeListFilter"], ["is_safe" => ["html"]]), |
|
74
|
|
|
|
|
75
|
|
|
new Twig_SimpleFilter("fontAwesomeListIcon", [$this, "fontAwesomeListIconFilter"], ["is_safe" => ["html"]]), |
|
76
|
|
|
new Twig_SimpleFilter("faListIcon", [$this, "fontAwesomeListIconFilter"], ["is_safe" => ["html"]]), |
|
77
|
|
|
]; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Get the Twig functions. |
|
82
|
|
|
* |
|
83
|
|
|
* @return array Returns the Twig functions. |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getFunctions() { |
|
86
|
|
|
return [ |
|
87
|
|
|
new Twig_SimpleFunction("fontAwesomeIcon", [$this, "fontAwesomeIconFunction"], ["is_safe" => ["html"]]), |
|
88
|
|
|
new Twig_SimpleFunction("faIcon", [$this, "fontAwesomeIconFunction"], ["is_safe" => ["html"]]), |
|
89
|
|
|
]; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
|
|
public function renderIcon($name, $style) { |
|
96
|
|
|
return $this->fontAwesomeIconFunction(["name" => $name, "style" => $style]); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|