1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the bootstrap-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\BootstrapBundle\Twig\Extension\Component; |
13
|
|
|
|
14
|
|
|
use Twig\TwigFunction; |
15
|
|
|
use WBW\Bundle\BootstrapBundle\Alert\AlertFactory; |
16
|
|
|
use WBW\Bundle\CoreBundle\Navigation\NavigationInterface; |
17
|
|
|
use WBW\Library\Core\Argument\ArrayHelper; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Alert Twig extension. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component |
24
|
|
|
* @link https://getbootstrap.com/docs/3.3/components/#alerts |
25
|
|
|
*/ |
26
|
|
|
class AlertTwigExtension extends AbstractAlertTwigExtension { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Service name. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
const SERVICE_NAME = "wbw.bootstrap.twig.extension.component.alert"; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Displays a Bootstrap alert "danger". |
37
|
|
|
* |
38
|
|
|
* @param array $args The arguments. |
39
|
|
|
* @return string Returns the Bootstrap alert "danger". |
40
|
|
|
*/ |
41
|
|
|
public function bootstrapAlertDangerFunction(array $args = []) { |
42
|
|
|
return $this->bootstrapAlert(AlertFactory::parseDangerAlert($args)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Displays a Bootstrap alert "dark". |
47
|
|
|
* |
48
|
|
|
* @param array $args The arguments. |
49
|
|
|
* @return string Returns the Bootstrap alert "dark". |
50
|
|
|
*/ |
51
|
|
|
public function bootstrapAlertDarkFunction(array $args = []) { |
52
|
|
|
return $this->bootstrapAlert(AlertFactory::parseDarkAlert($args)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Displays a Bootstrap alert "info". |
57
|
|
|
* |
58
|
|
|
* @param array $args The arguments. |
59
|
|
|
* @return string Returns the Bootstrap alert "info". |
60
|
|
|
*/ |
61
|
|
|
public function bootstrapAlertInfoFunction(array $args = []) { |
62
|
|
|
return $this->bootstrapAlert(AlertFactory::parseInfoAlert($args)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Displays a Bootstrap alert "light". |
67
|
|
|
* |
68
|
|
|
* @param array $args The arguments. |
69
|
|
|
* @return string Returns the Bootstrap alert "light". |
70
|
|
|
*/ |
71
|
|
|
public function bootstrapAlertLightFunction(array $args = []) { |
72
|
|
|
return $this->bootstrapAlert(AlertFactory::parseLightAlert($args)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Displays a Bootstrap alert "link". |
77
|
|
|
* |
78
|
|
|
* @param array $args The arguments. |
79
|
|
|
* @return string Returns the Bootstrap alert "link". |
80
|
|
|
*/ |
81
|
|
|
public function bootstrapAlertLinkFunction(array $args = []) { |
82
|
|
|
|
83
|
|
|
$attributes = []; |
84
|
|
|
|
85
|
|
|
$attributes["href"] = ArrayHelper::get($args, "href", NavigationInterface::NAVIGATION_HREF_DEFAULT); |
86
|
|
|
|
87
|
|
|
$innerHTML = ArrayHelper::get($args, "content"); |
88
|
|
|
|
89
|
|
|
return static::coreHTMLElement("a", $innerHTML, $attributes); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Displays a Bootstrap alert "secondary". |
94
|
|
|
* |
95
|
|
|
* @param array $args The arguments. |
96
|
|
|
* @return string Returns the Bootstrap alert "secondary". |
97
|
|
|
*/ |
98
|
|
|
public function bootstrapAlertSecondaryFunction(array $args = []) { |
99
|
|
|
return $this->bootstrapAlert(AlertFactory::parseSecondaryAlert($args)); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Displays a Bootstrap alert "success". |
104
|
|
|
* |
105
|
|
|
* @param array $args The arguments. |
106
|
|
|
* @return string Returns the Bootstrap alert "success". |
107
|
|
|
*/ |
108
|
|
|
public function bootstrapAlertSuccessFunction(array $args = []) { |
109
|
|
|
return $this->bootstrapAlert(AlertFactory::parseSuccessAlert($args)); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Displays a Bootstrap alert "warning". |
114
|
|
|
* |
115
|
|
|
* @param array $args The arguments. |
116
|
|
|
* @return string Returns the Bootstrap alert "warning". |
117
|
|
|
*/ |
118
|
|
|
public function bootstrapAlertWarningFunction(array $args = []) { |
119
|
|
|
return $this->bootstrapAlert(AlertFactory::parseWarningAlert($args)); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Get the Twig functions. |
124
|
|
|
* |
125
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
126
|
|
|
*/ |
127
|
|
|
public function getFunctions() { |
128
|
|
|
|
129
|
|
|
$functions3 = $this->getFunctions3(); |
130
|
|
|
if (3 === $this->getVersion()) { |
131
|
|
|
return $functions3; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$functions4 = $this->getFunctions4(); |
135
|
|
|
|
136
|
|
|
return array_merge($functions3, $functions4); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Get the Twig functions. |
141
|
|
|
* |
142
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
143
|
|
|
*/ |
144
|
|
|
protected function getFunctions3() { |
145
|
|
|
return [ |
146
|
|
|
new TwigFunction("bootstrapAlertDanger", [$this, "bootstrapAlertDangerFunction"], ["is_safe" => ["html"]]), |
147
|
|
|
new TwigFunction("bsAlertDanger", [$this, "bootstrapAlertDangerFunction"], ["is_safe" => ["html"]]), |
148
|
|
|
|
149
|
|
|
new TwigFunction("bootstrapAlertInfo", [$this, "bootstrapAlertInfoFunction"], ["is_safe" => ["html"]]), |
150
|
|
|
new TwigFunction("bsAlertInfo", [$this, "bootstrapAlertInfoFunction"], ["is_safe" => ["html"]]), |
151
|
|
|
|
152
|
|
|
new TwigFunction("bootstrapAlertSuccess", [$this, "bootstrapAlertSuccessFunction"], ["is_safe" => ["html"]]), |
153
|
|
|
new TwigFunction("bsAlertSuccess", [$this, "bootstrapAlertSuccessFunction"], ["is_safe" => ["html"]]), |
154
|
|
|
|
155
|
|
|
new TwigFunction("bootstrapAlertWarning", [$this, "bootstrapAlertWarningFunction"], ["is_safe" => ["html"]]), |
156
|
|
|
new TwigFunction("bsAlertWarning", [$this, "bootstrapAlertWarningFunction"], ["is_safe" => ["html"]]), |
157
|
|
|
]; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Get the Twig functions. |
162
|
|
|
* |
163
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
164
|
|
|
*/ |
165
|
|
|
protected function getFunctions4() { |
166
|
|
|
return [ |
167
|
|
|
new TwigFunction("bootstrapAlertDark", [$this, "bootstrapAlertDarkFunction"], ["is_safe" => ["html"]]), |
168
|
|
|
new TwigFunction("bsAlertDark", [$this, "bootstrapAlertDarkFunction"], ["is_safe" => ["html"]]), |
169
|
|
|
|
170
|
|
|
new TwigFunction("bootstrapAlertLight", [$this, "bootstrapAlertLightFunction"], ["is_safe" => ["html"]]), |
171
|
|
|
new TwigFunction("bsAlertLight", [$this, "bootstrapAlertLightFunction"], ["is_safe" => ["html"]]), |
172
|
|
|
|
173
|
|
|
new TwigFunction("bootstrapAlertLink", [$this, "bootstrapAlertLinkFunction"], ["is_safe" => ["html"]]), |
174
|
|
|
new TwigFunction("bsAlertLink", [$this, "bootstrapAlertLinkFunction"], ["is_safe" => ["html"]]), |
175
|
|
|
|
176
|
|
|
new TwigFunction("bootstrapAlertSecondary", [$this, "bootstrapAlertSecondaryFunction"], ["is_safe" => ["html"]]), |
177
|
|
|
new TwigFunction("bsAlertSecondary", [$this, "bootstrapAlertSecondaryFunction"], ["is_safe" => ["html"]]), |
178
|
|
|
]; |
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|