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\Assets; |
13
|
|
|
|
14
|
|
|
use WBW\Bundle\CoreBundle\Assets\Icon\FontAwesomeIconInterface; |
15
|
|
|
use WBW\Bundle\CoreBundle\Renderer\Assets\FontAwesomeIconRenderer; |
16
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\AbstractTwigExtension; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Abstract Font Awesome Twig extension. |
20
|
|
|
* |
21
|
|
|
* @author webeweb <https://github.com/webeweb> |
22
|
|
|
* @package WBW\Bundle\CoreBundle\Twig\Extension\Assets |
23
|
|
|
* @abstract |
24
|
|
|
*/ |
25
|
|
|
abstract class AbstractFontAwesomeTwigExtension extends AbstractTwigExtension { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Display a Font Awesome icon. |
29
|
|
|
* |
30
|
|
|
* @param FontAwesomeIconInterface $icon The icon. |
31
|
|
|
* @return string Returns the Font Awesome icon. |
32
|
|
|
*/ |
33
|
|
|
protected function fontAwesomeIcon(FontAwesomeIconInterface $icon): string { |
34
|
|
|
|
35
|
|
|
$attributes = [ |
36
|
|
|
"class" => [ |
37
|
|
|
FontAwesomeIconRenderer::renderFont($icon), |
38
|
|
|
FontAwesomeIconRenderer::renderName($icon), |
39
|
|
|
FontAwesomeIconRenderer::renderSize($icon), |
40
|
|
|
FontAwesomeIconRenderer::renderFixedWidth($icon), |
41
|
|
|
FontAwesomeIconRenderer::renderBordered($icon), |
42
|
|
|
FontAwesomeIconRenderer::renderPull($icon), |
43
|
|
|
FontAwesomeIconRenderer::renderAnimation($icon), |
44
|
|
|
], |
45
|
|
|
"style" => FontAwesomeIconRenderer::renderStyle($icon), |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
return static::coreHtmlElement("i", null, $attributes); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Display a Font Awesome list. |
53
|
|
|
* |
54
|
|
|
* @param array|string $items The items. |
55
|
|
|
* @return string Returns the Font Awesome list. |
56
|
|
|
*/ |
57
|
|
|
protected function fontAwesomeList($items): string { |
58
|
|
|
|
59
|
|
|
$innerHTML = true === is_array($items) ? implode("\n", $items) : $items; |
60
|
|
|
|
61
|
|
|
return static::coreHtmlElement("ul", $innerHTML, ["class" => "fa-ul"]); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Display a Font Awesome list icon. |
66
|
|
|
* |
67
|
|
|
* @param string $icon The icon. |
68
|
|
|
* @param string|null $content The content. |
69
|
|
|
* @return string Returns the Font Awesome list icon. |
70
|
|
|
*/ |
71
|
|
|
protected function fontAwesomeListIcon(string $icon, ?string $content): string { |
72
|
|
|
|
73
|
|
|
$glyphicon = static::coreHtmlElement("span", $icon, ["class" => "fa-li"]); |
74
|
|
|
$innerHTML = null !== $content ? $content : ""; |
75
|
|
|
|
76
|
|
|
return static::coreHtmlElement("li", $glyphicon . $innerHTML); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|