1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the adminbsb-material-design-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2017 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\AdminBSBBundle\Twig\Extension\UI; |
13
|
|
|
|
14
|
|
|
use Twig_SimpleFilter; |
15
|
|
|
use Twig_SimpleFunction; |
16
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractTwigExtension; |
17
|
|
|
use WBW\Library\Core\Argument\ArrayHelper; |
18
|
|
|
use WBW\Library\Core\Argument\StringHelper; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Button Twig extension. |
22
|
|
|
* |
23
|
|
|
* @author webeweb <https://github.com/webeweb/> |
24
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\UI |
25
|
|
|
*/ |
26
|
|
|
class ButtonTwigExtension extends AbstractButtonTwigExtension { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Service name. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
const SERVICE_NAME = "webeweb.adminbsb.twig.extension.ui.button"; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Displays an AdminBSB button "Danger". |
37
|
|
|
* |
38
|
|
|
* @param array $args The arguments. |
39
|
|
|
* @return string Returns the AdminBSB button "Danger". |
40
|
|
|
*/ |
41
|
|
|
public function adminBSBButtonDangerFunction(array $args = []) { |
42
|
|
|
return $this->adminBSBButton(ArrayHelper::get($args, "content"), ArrayHelper::get($args, "title"), ArrayHelper::get($args, "size", false), ArrayHelper::get($args, "block", false), ArrayHelper::get($args, "disable", false), "btn-danger", ArrayHelper::get($args, "icon"), ArrayHelper::get($args, "circle", false)); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Displays an AdminBSB button "Default". |
47
|
|
|
* |
48
|
|
|
* @param array $args The arguments. |
49
|
|
|
* @return string Returns the AdminBSB button "Default". |
50
|
|
|
*/ |
51
|
|
|
public function adminBSBButtonDefaultFunction(array $args = []) { |
52
|
|
|
return $this->adminBSBButton(ArrayHelper::get($args, "content"), ArrayHelper::get($args, "title"), ArrayHelper::get($args, "size", false), ArrayHelper::get($args, "block", false), ArrayHelper::get($args, "disable", false), "btn-default", ArrayHelper::get($args, "icon"), ArrayHelper::get($args, "circle", false)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Displays an AdminBSB button "Info". |
57
|
|
|
* |
58
|
|
|
* @param array $args The arguments. |
59
|
|
|
* @return string Returns the AdminBSB button "Info". |
60
|
|
|
*/ |
61
|
|
|
public function adminBSBButtonInfoFunction(array $args = []) { |
62
|
|
|
return $this->adminBSBButton(ArrayHelper::get($args, "content"), ArrayHelper::get($args, "title"), ArrayHelper::get($args, "size", false), ArrayHelper::get($args, "block", false), ArrayHelper::get($args, "disable", false), "btn-info", ArrayHelper::get($args, "icon"), ArrayHelper::get($args, "circle", false)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Displays an AdminBSB button "Link". |
67
|
|
|
* |
68
|
|
|
* @param string $button The button. |
69
|
|
|
* @param string $link The link. |
70
|
|
|
* @return string Returns the AdminBSB button "Link". |
71
|
|
|
*/ |
72
|
|
|
public function adminBSBButtonLinkFilter($button, $link = self::DEFAULT_HREF) { |
73
|
|
|
$searches = ["<button", "type=\"button\"", "</button>"]; |
74
|
|
|
$replaces = ["<a", "href=\"" . $link . "\"", "</a>"]; |
75
|
|
|
return StringHelper::replace($button, $searches, $replaces); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Displays a AdminBSB button "Material design". |
80
|
|
|
* |
81
|
|
|
* @param array $args The arguments. |
82
|
|
|
* @return string Returns the AdminBSB button "Material design". |
83
|
|
|
*/ |
84
|
|
|
public function adminBSBButtonMaterialDesignFunction(array $args = []) { |
85
|
|
|
return $this->adminBSBButton(ArrayHelper::get($args, "content"), ArrayHelper::get($args, "title"), ArrayHelper::get($args, "size", false), ArrayHelper::get($args, "block", false), ArrayHelper::get($args, "disable", false), AbstractTwigExtension::fixColor(ArrayHelper::get($args, "color", "red"), "bg-"), ArrayHelper::get($args, "icon"), ArrayHelper::get($args, "circle", false)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Displays an AdminBSB button "Primary". |
90
|
|
|
* |
91
|
|
|
* @param array $args The arguments. |
92
|
|
|
* @return string Returns the AdminBSB button "Primary". |
93
|
|
|
*/ |
94
|
|
|
public function adminBSBButtonPrimaryFunction(array $args = []) { |
95
|
|
|
return $this->adminBSBButton(ArrayHelper::get($args, "content"), ArrayHelper::get($args, "title"), ArrayHelper::get($args, "size", false), ArrayHelper::get($args, "block", false), ArrayHelper::get($args, "disable", false), "btn-primary", ArrayHelper::get($args, "icon"), ArrayHelper::get($args, "circle", false)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Displays an AdminBSB button "Success". |
100
|
|
|
* |
101
|
|
|
* @param array $args The arguments. |
102
|
|
|
* @return string Returns the AdminBSB button "Success". |
103
|
|
|
*/ |
104
|
|
|
public function adminBSBButtonSuccessFunction(array $args = []) { |
105
|
|
|
return $this->adminBSBButton(ArrayHelper::get($args, "content"), ArrayHelper::get($args, "title"), ArrayHelper::get($args, "size", false), ArrayHelper::get($args, "block", false), ArrayHelper::get($args, "disable", false), "btn-success", ArrayHelper::get($args, "icon"), ArrayHelper::get($args, "circle", false)); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Displays an AdminBSB button "Warning". |
110
|
|
|
* |
111
|
|
|
* @param array $args The arguments. |
112
|
|
|
* @return string Returns the AdminBSB button "Warning". |
113
|
|
|
*/ |
114
|
|
|
public function adminBSBButtonWarningFunction(array $args = []) { |
115
|
|
|
return $this->adminBSBButton(ArrayHelper::get($args, "content"), ArrayHelper::get($args, "title"), ArrayHelper::get($args, "size", false), ArrayHelper::get($args, "block", false), ArrayHelper::get($args, "disable", false), "btn-warning", ArrayHelper::get($args, "icon"), ArrayHelper::get($args, "circle", false)); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get the Twig filters. |
120
|
|
|
* |
121
|
|
|
* @return array Returns the Twig filters. |
122
|
|
|
*/ |
123
|
|
|
public function getFilters() { |
124
|
|
|
return [ |
125
|
|
|
new Twig_SimpleFilter("adminBSBButtonLink", [$this, "adminBSBButtonLinkFilter"], ["is_safe" => ["html"]]), |
126
|
|
|
]; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Get the Twig functions. |
131
|
|
|
* |
132
|
|
|
* @return array Returns the Twig functions. |
133
|
|
|
*/ |
134
|
|
|
public function getFunctions() { |
135
|
|
|
return [ |
136
|
|
|
new Twig_SimpleFunction("adminBSBButtonDanger", [$this, "adminBSBButtonDangerFunction"], ["is_safe" => ["html"]]), |
137
|
|
|
new Twig_SimpleFunction("adminBSBButtonDefault", [$this, "adminBSBButtonDefaultFunction"], ["is_safe" => ["html"]]), |
138
|
|
|
new Twig_SimpleFunction("adminBSBButtonInfo", [$this, "adminBSBButtonInfoFunction"], ["is_safe" => ["html"]]), |
139
|
|
|
new Twig_SimpleFunction("adminBSBButtonMaterialDesign", [$this, "adminBSBButtonMaterialDesignFunction"], ["is_safe" => ["html"]]), |
140
|
|
|
new Twig_SimpleFunction("adminBSBButtonPrimary", [$this, "adminBSBButtonPrimaryFunction"], ["is_safe" => ["html"]]), |
141
|
|
|
new Twig_SimpleFunction("adminBSBButtonSuccess", [$this, "adminBSBButtonSuccessFunction"], ["is_safe" => ["html"]]), |
142
|
|
|
new Twig_SimpleFunction("adminBSBButtonWarning", [$this, "adminBSBButtonWarningFunction"], ["is_safe" => ["html"]]), |
143
|
|
|
]; |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|