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