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\Twig\Extension\AbstractTwigExtension; |
16
|
|
|
use WBW\Library\Core\Argument\StringHelper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Abstract Material Design Iconic Font Twig extension. |
20
|
|
|
* |
21
|
|
|
* @author webeweb <https://github.com/webeweb/> |
22
|
|
|
* @package WBW\Bundle\Core\Twig\Extension\Plugin |
23
|
|
|
* @abstract |
24
|
|
|
*/ |
25
|
|
|
abstract class AbstractMaterialDesignIconicFontTwigExtension extends AbstractTwigExtension { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Constructor. |
29
|
|
|
* |
30
|
|
|
* @param Twig_Environment $twigEnvironment The twig environment. |
31
|
|
|
*/ |
32
|
|
|
protected function __construct(Twig_Environment $twigEnvironment) { |
33
|
|
|
parent::__construct($twigEnvironment); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Displays a Material Design Iconic Font icon. |
38
|
|
|
* |
39
|
|
|
* @param string $name The name. |
40
|
|
|
* @param string $size The size. |
41
|
|
|
* @param bool $fixedWidth Fixed width ? |
42
|
|
|
* @param string $border The border |
43
|
|
|
* @param string $pull The pull. |
44
|
|
|
* @param string $spin The spin. |
45
|
|
|
* @param string $rotate The rotate. |
46
|
|
|
* @param string $flip The flip. |
47
|
|
|
* @param string $style The style. |
48
|
|
|
* @return string Returns the Material Design Iconic Font icon. |
49
|
|
|
*/ |
50
|
|
|
protected function materialDesignIconicFontIcon($name, $size, $fixedWidth, $border, $pull, $spin, $rotate, $flip, $style) { |
51
|
|
|
|
52
|
|
|
// Initialize the values. |
53
|
|
|
$sizes = ["lg", "2x", "3x", "4x", "5x"]; |
54
|
|
|
$borders = ["border", "border-circle"]; |
55
|
|
|
$pulls = ["left", "right"]; |
56
|
|
|
$spins = ["spin", "spin-reverse"]; |
57
|
|
|
$rotates = ["90", "180", "270"]; |
58
|
|
|
$flips = ["horizontal", "vertical"]; |
59
|
|
|
|
60
|
|
|
// Initialize the attributes. |
61
|
|
|
$attributes = []; |
62
|
|
|
|
63
|
|
|
$attributes["class"][] = "zmdi"; |
64
|
|
|
$attributes["class"][] = null !== $name ? "zmdi-" . $name : null; |
65
|
|
|
$attributes["class"][] = true === in_array($size, $sizes) ? "zmdi-hc-" . $size : null; |
66
|
|
|
$attributes["class"][] = true === $fixedWidth ? "zmdi-hc-fw" : null; |
67
|
|
|
$attributes["class"][] = true === in_array($border, $borders) ? "zmdi-hc-" . $border : null; |
68
|
|
|
$attributes["class"][] = true === in_array($pull, $pulls) ? "pull-" . $pull : null; |
69
|
|
|
$attributes["class"][] = true === in_array($spin, $spins) ? "zmdi-hc-" . $spin : null; |
70
|
|
|
$attributes["class"][] = true === in_array($rotate, $rotates) ? "zmdi-hc-rotate-" . $rotate : null; |
71
|
|
|
$attributes["class"][] = true === in_array($flip, $flips) ? "zmdi-hc-flip-" . $flip : null; |
72
|
|
|
$attributes["style"] = $style; |
73
|
|
|
|
74
|
|
|
// Return the HTML. |
75
|
|
|
return static::coreHTMLElement("i", null, $attributes); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Displays a Material Design Iconic Font list. |
80
|
|
|
* |
81
|
|
|
* @param array|string $items The items. |
82
|
|
|
* @return string Returns the Material Design Iconic Font list. |
83
|
|
|
*/ |
84
|
|
|
protected function materialDesignIconicFontList($items) { |
85
|
|
|
|
86
|
|
|
// Initialize the parameters. |
87
|
|
|
$innerHTML = true === is_array($items) ? implode("\n", $items) : $items; |
88
|
|
|
|
89
|
|
|
// Return the HTML. |
90
|
|
|
return static::coreHTMLElement("ul", $innerHTML, ["class" => "zmdi-hc-ul"]); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Displays a Material Design Iconic Font list icon. |
95
|
|
|
* |
96
|
|
|
* @param string $icon The icon. |
97
|
|
|
* @param string $content The content. |
98
|
|
|
* @return string Returns the Material Design Iconic Font list icon. |
99
|
|
|
*/ |
100
|
|
|
protected function materialDesignIconicFontListIcon($icon, $content) { |
101
|
|
|
|
102
|
|
|
// Initialize the parameters. |
103
|
|
|
$glyphicon = null !== $icon ? StringHelper::replace($icon, ["class=\"zmdi"], ["class=\"zmdi-hc-li zmdi"]) : ""; |
104
|
|
|
$innerHTML = null !== $content ? $content : ""; |
105
|
|
|
|
106
|
|
|
// Return the HTML. |
107
|
|
|
return static::coreHTMLElement("li", $glyphicon . $innerHTML); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|