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_SimpleFilter; |
15
|
|
|
use Twig_SimpleFunction; |
16
|
|
|
use WBW\Library\Core\Utility\ArrayUtility; |
17
|
|
|
use WBW\Library\Core\Utility\StringUtility; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* ButtonComponentTwigExtension. |
21
|
|
|
* |
22
|
|
|
* @author Camille A. <[email protected]> |
23
|
|
|
* @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component |
24
|
|
|
*/ |
25
|
|
|
final class ButtonComponentTwigExtension extends AbstractComponentTwigExtension { |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Service name. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
const SERVICE_NAME = "webeweb.bundle.bootstrapbundle.twig.extension.component.button"; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Displays a Bootstrap button "Danger". |
36
|
|
|
* |
37
|
|
|
* @param array $args The arguments. |
38
|
|
|
* @return string Returns the Bootstrap button "Danger". |
39
|
|
|
*/ |
40
|
|
|
public function bootstrapButtonDangerFunction(array $args = []) { |
41
|
|
|
return $this->bootstrapButton(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "title"), ArrayUtility::get($args, "size", false), ArrayUtility::get($args, "block", false), ArrayUtility::get($args, "active", false), ArrayUtility::get($args, "disable", false), "btn-danger", ArrayUtility::get($args, "icon")); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Displays a Bootstrap button "Default". |
46
|
|
|
* |
47
|
|
|
* @param array $args The arguments. |
48
|
|
|
* @return string Returns the Bootstrap button "Default". |
49
|
|
|
*/ |
50
|
|
|
public function bootstrapButtonDefaultFunction(array $args = []) { |
51
|
|
|
return $this->bootstrapButton(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "title"), ArrayUtility::get($args, "size", false), ArrayUtility::get($args, "block", false), ArrayUtility::get($args, "active", false), ArrayUtility::get($args, "disable", false), "btn-default", ArrayUtility::get($args, "icon")); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Displays a Bootstrap button "Info". |
56
|
|
|
* |
57
|
|
|
* @param array $args The arguments. |
58
|
|
|
* @return string Returns the Bootstrap button "Info". |
59
|
|
|
*/ |
60
|
|
|
public function bootstrapButtonInfoFunction(array $args = []) { |
61
|
|
|
return $this->bootstrapButton(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "title"), ArrayUtility::get($args, "size", false), ArrayUtility::get($args, "block", false), ArrayUtility::get($args, "active", false), ArrayUtility::get($args, "disable", false), "btn-info", ArrayUtility::get($args, "icon")); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Transforms a Bootstrap button into an anchor. |
66
|
|
|
* |
67
|
|
|
* @param string $bootstrapButton |
68
|
|
|
* @param string $href The href attribute. |
69
|
|
|
* @return string Returns the Bootstrap button transformed into an anchor. |
70
|
|
|
*/ |
71
|
|
|
public function bootstrapButtonLinkFilter($bootstrapButton, $href = self::DEFAULT_HREF) { |
72
|
|
|
return StringUtility::replace($bootstrapButton, ["<button", "type=\"button\"", "</button>"], ["<a", "href=\"" . $href . "\"", "</a>"]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Displays a Bootstrap button "Link". |
77
|
|
|
* |
78
|
|
|
* @param array $args The arguments. |
79
|
|
|
* @return string Returns the Bootstrap button "Link". |
80
|
|
|
*/ |
81
|
|
|
public function bootstrapButtonLinkFunction(array $args = []) { |
82
|
|
|
return $this->bootstrapButton(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "title"), ArrayUtility::get($args, "size", false), ArrayUtility::get($args, "block", false), ArrayUtility::get($args, "active", false), ArrayUtility::get($args, "disable", false), "btn-link", ArrayUtility::get($args, "icon")); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Displays a Bootstrap button "Primary". |
87
|
|
|
* |
88
|
|
|
* @param array $args The arguments. |
89
|
|
|
* @return string Returns the Bootstrap button "Primary". |
90
|
|
|
*/ |
91
|
|
|
public function bootstrapButtonPrimaryFunction(array $args = []) { |
92
|
|
|
return $this->bootstrapButton(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "title"), ArrayUtility::get($args, "size", false), ArrayUtility::get($args, "block", false), ArrayUtility::get($args, "active", false), ArrayUtility::get($args, "disable", false), "btn-primary", ArrayUtility::get($args, "icon")); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Displays a Bootstrap button "Success". |
97
|
|
|
* |
98
|
|
|
* @param array $args The arguments. |
99
|
|
|
* @return string Returns the Bootstrap button "Success". |
100
|
|
|
*/ |
101
|
|
|
public function bootstrapButtonSuccessFunction(array $args = []) { |
102
|
|
|
return $this->bootstrapButton(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "title"), ArrayUtility::get($args, "size", false), ArrayUtility::get($args, "block", false), ArrayUtility::get($args, "active", false), ArrayUtility::get($args, "disable", false), "btn-success", ArrayUtility::get($args, "icon")); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Displays a Bootstrap button "Warning". |
107
|
|
|
* |
108
|
|
|
* @param array $args The arguments. |
109
|
|
|
* @return string Returns the Bootstrap button "Warning". |
110
|
|
|
*/ |
111
|
|
|
public function bootstrapButtonWarningFunction(array $args = []) { |
112
|
|
|
return $this->bootstrapButton(ArrayUtility::get($args, "content"), ArrayUtility::get($args, "title"), ArrayUtility::get($args, "size", false), ArrayUtility::get($args, "block", false), ArrayUtility::get($args, "active", false), ArrayUtility::get($args, "disable", false), "btn-warning", ArrayUtility::get($args, "icon")); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Get the Twig filters. |
117
|
|
|
* |
118
|
|
|
* @return Twig_SimpleFilter[] Returns the Twig filters. |
119
|
|
|
*/ |
120
|
|
|
public function getFilters() { |
121
|
|
|
return [ |
122
|
|
|
new Twig_SimpleFilter("bootstrapButtonLink", [$this, "bootstrapButtonLinkFilter"], ["is_safe" => ["html"]]), |
123
|
|
|
]; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Get the Twig functions. |
128
|
|
|
* |
129
|
|
|
* @return Twig_SimpleFunction[] Returns the Twig functions. |
130
|
|
|
*/ |
131
|
|
|
public function getFunctions() { |
132
|
|
|
return [ |
133
|
|
|
new Twig_SimpleFunction("bootstrapButtonDanger", [$this, "bootstrapButtonDangerFunction"], ["is_safe" => ["html"]]), |
134
|
|
|
new Twig_SimpleFunction("bootstrapButtonDefault", [$this, "bootstrapButtonDefaultFunction"], ["is_safe" => ["html"]]), |
135
|
|
|
new Twig_SimpleFunction("bootstrapButtonInfo", [$this, "bootstrapButtonInfoFunction"], ["is_safe" => ["html"]]), |
136
|
|
|
new Twig_SimpleFunction("bootstrapButtonLink", [$this, "bootstrapButtonLinkFunction"], ["is_safe" => ["html"]]), |
137
|
|
|
new Twig_SimpleFunction("bootstrapButtonPrimary", [$this, "bootstrapButtonPrimaryFunction"], ["is_safe" => ["html"]]), |
138
|
|
|
new Twig_SimpleFunction("bootstrapButtonSuccess", [$this, "bootstrapButtonSuccessFunction"], ["is_safe" => ["html"]]), |
139
|
|
|
new Twig_SimpleFunction("bootstrapButtonWarning", [$this, "bootstrapButtonWarningFunction"], ["is_safe" => ["html"]]), |
140
|
|
|
]; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
} |
144
|
|
|
|