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