1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the bootstrap-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2018 NdC/WBW |
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\Library\Core\Utility\ArrayUtility; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Alert component Twig extension. |
19
|
|
|
* |
20
|
|
|
* @author NdC/WBW <https://github.com/webeweb/> |
21
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component |
22
|
|
|
* @final |
23
|
|
|
*/ |
24
|
|
|
final class AlertComponentTwigExtension extends AbstractComponentTwigExtension { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Service name. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.component.alert"; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Displays a Bootstrap alert "Danger". |
35
|
|
|
* |
36
|
|
|
* @param array $args The arguments. |
37
|
|
|
* @return string Returns the Bootstrap alert "Danger". |
38
|
|
|
*/ |
39
|
|
|
public function bootstrapAlertDangerFunction(array $args = []) { |
40
|
|
|
return $this->bootstrapAlert(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "dismissible"), "alert-danger"); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Displays a Bootstrap alert "Info". |
45
|
|
|
* |
46
|
|
|
* @param array $args The arguments. |
47
|
|
|
* @return string Returns the Bootstrap alert "Info". |
48
|
|
|
*/ |
49
|
|
|
public function bootstrapAlertInfoFunction(array $args = []) { |
50
|
|
|
return $this->bootstrapAlert(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "dismissible"), "alert-info"); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Displays a Bootstrap alert "Success". |
55
|
|
|
* |
56
|
|
|
* @param array $args The arguments. |
57
|
|
|
* @return string Returns the Bootstrap alert "Success". |
58
|
|
|
*/ |
59
|
|
|
public function bootstrapAlertSuccessFunction(array $args = []) { |
60
|
|
|
return $this->bootstrapAlert(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "dismissible"), "alert-success"); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Displays a Bootstrap alert "Warning". |
65
|
|
|
* |
66
|
|
|
* @param array $args The arguments. |
67
|
|
|
* @return string Returns the Bootstrap alert "Warning". |
68
|
|
|
*/ |
69
|
|
|
public function bootstrapAlertWarningFunction(array $args = []) { |
70
|
|
|
return $this->bootstrapAlert(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "dismissible"), "alert-warning"); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the Twig functions. |
75
|
|
|
* |
76
|
|
|
* @return array Returns the Twig functions. |
77
|
|
|
*/ |
78
|
|
|
public function getFunctions() { |
79
|
|
|
return [ |
80
|
|
|
new Twig_SimpleFunction("bootstrapAlertDanger", [$this, "bootstrapAlertDangerFunction"], ["is_safe" => ["html"]]), |
81
|
|
|
new Twig_SimpleFunction("bootstrapAlertInfo", [$this, "bootstrapAlertInfoFunction"], ["is_safe" => ["html"]]), |
82
|
|
|
new Twig_SimpleFunction("bootstrapAlertSuccess", [$this, "bootstrapAlertSuccessFunction"], ["is_safe" => ["html"]]), |
83
|
|
|
new Twig_SimpleFunction("bootstrapAlertWarning", [$this, "bootstrapAlertWarningFunction"], ["is_safe" => ["html"]]), |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|