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_SimpleFunction; |
15
|
|
|
use WBW\Bundle\BootstrapBundle\Navigation\NavigationInterface; |
16
|
|
|
use WBW\Library\Core\Utility\Argument\ArrayUtility; |
17
|
|
|
use WBW\Library\Core\Utility\Argument\StringUtility; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Alert component Twig extension. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component |
24
|
|
|
*/ |
25
|
|
|
class AlertComponentTwigExtension extends AbstractComponentTwigExtension { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Service name. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.component.alert"; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor. |
36
|
|
|
*/ |
37
|
|
|
public function __construct() { |
38
|
|
|
parent::__construct(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Displays a Bootstrap alert "Danger". |
43
|
|
|
* |
44
|
|
|
* @param array $args The arguments. |
45
|
|
|
* @return string Returns the Bootstrap alert "Danger". |
46
|
|
|
*/ |
47
|
|
|
public function bootstrapAlertDangerFunction(array $args = []) { |
48
|
|
|
return $this->bootstrapAlert(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "dismissible"), "alert-danger"); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Displays a Bootstrap alert "Info". |
53
|
|
|
* |
54
|
|
|
* @param array $args The arguments. |
55
|
|
|
* @return string Returns the Bootstrap alert "Info". |
56
|
|
|
*/ |
57
|
|
|
public function bootstrapAlertInfoFunction(array $args = []) { |
58
|
|
|
return $this->bootstrapAlert(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "dismissible"), "alert-info"); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Displays a Bootstrap alert "Link". |
63
|
|
|
* |
64
|
|
|
* @param array $args The arguments. |
65
|
|
|
* @return string Returns the Bootstrap alert "Link". |
66
|
|
|
*/ |
67
|
|
|
public function bootstrapAlertLinkFunction(array $args = []) { |
68
|
|
|
|
69
|
|
|
// Initialize the template. |
70
|
|
|
$template = "<a %attributes%>%innerHTML%</a>"; |
71
|
|
|
|
72
|
|
|
// Initialize the attributes. |
73
|
|
|
$attributes = []; |
74
|
|
|
|
75
|
|
|
$attributes["href"] = ArrayUtility::get($args, "href", NavigationInterface::DEFAULT_HREF); |
76
|
|
|
|
77
|
|
|
// Initialize the parameters. |
78
|
|
|
$innerHTML = ArrayUtility::get($args, "content"); |
79
|
|
|
|
80
|
|
|
// Return the HTML. |
81
|
|
|
return StringUtility::replace($template, ["%attributes%", "%innerHTML%"], [StringUtility::parseArray($attributes), $innerHTML]); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Displays a Bootstrap alert "Success". |
86
|
|
|
* |
87
|
|
|
* @param array $args The arguments. |
88
|
|
|
* @return string Returns the Bootstrap alert "Success". |
89
|
|
|
*/ |
90
|
|
|
public function bootstrapAlertSuccessFunction(array $args = []) { |
91
|
|
|
return $this->bootstrapAlert(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "dismissible"), "alert-success"); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Displays a Bootstrap alert "Warning". |
96
|
|
|
* |
97
|
|
|
* @param array $args The arguments. |
98
|
|
|
* @return string Returns the Bootstrap alert "Warning". |
99
|
|
|
*/ |
100
|
|
|
public function bootstrapAlertWarningFunction(array $args = []) { |
101
|
|
|
return $this->bootstrapAlert(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "dismissible"), "alert-warning"); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get the Twig functions. |
106
|
|
|
* |
107
|
|
|
* @return Twig_SimpleFunction[] Returns the Twig functions. |
108
|
|
|
*/ |
109
|
|
|
public function getFunctions() { |
110
|
|
|
return [ |
111
|
|
|
new Twig_SimpleFunction("bootstrapAlertDanger", [$this, "bootstrapAlertDangerFunction"], ["is_safe" => ["html"]]), |
112
|
|
|
new Twig_SimpleFunction("bootstrapAlertInfo", [$this, "bootstrapAlertInfoFunction"], ["is_safe" => ["html"]]), |
113
|
|
|
new Twig_SimpleFunction("bootstrapAlertLink", [$this, "bootstrapAlertLinkFunction"], ["is_safe" => ["html"]]), |
114
|
|
|
new Twig_SimpleFunction("bootstrapAlertSuccess", [$this, "bootstrapAlertSuccessFunction"], ["is_safe" => ["html"]]), |
115
|
|
|
new Twig_SimpleFunction("bootstrapAlertWarning", [$this, "bootstrapAlertWarningFunction"], ["is_safe" => ["html"]]), |
116
|
|
|
]; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|