|
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\Form; |
|
13
|
|
|
|
|
14
|
|
|
use WBW\Bundle\AdminBSBBundle\Twig\Extension\AbstractTwigExtension; |
|
15
|
|
|
use WBW\Library\Core\Argument\StringHelper; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Abstract switch button Twig extension. |
|
19
|
|
|
* |
|
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
21
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Form |
|
22
|
|
|
* @abstract |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class AbstractSwitchButtonTwigExtension extends AbstractTwigExtension { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Displays an AdminBSB switch button. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $offLabel The off label. |
|
30
|
|
|
* @param string $name The name. |
|
31
|
|
|
* @param bool $checked Checked ? |
|
32
|
|
|
* @param bool $disabled Disable ? |
|
33
|
|
|
* @param string $onLabel The on label. |
|
34
|
|
|
* @param array $attrs The attributes. |
|
35
|
|
|
* @param string $class The class. |
|
36
|
|
|
* @return string Returns the AdminBSB switch button. |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function adminBSBSwitchButton($offLabel, $name, $checked, $disabled, $onLabel, array $attrs, $class) { |
|
39
|
|
|
|
|
40
|
|
|
$template = "<input %attributes%>%innerHTML%"; |
|
41
|
|
|
|
|
42
|
|
|
$attributes = $attrs; |
|
43
|
|
|
|
|
44
|
|
|
$attributes["name"] = $name; |
|
45
|
|
|
$attributes["type"] = "checkbox"; |
|
46
|
|
|
$attributes["checked"] = true === $checked ? "checked" : null; |
|
47
|
|
|
$attributes["disabled"] = true === $disabled ? "disabled" : null; |
|
48
|
|
|
|
|
49
|
|
|
$lLabel = null !== $offLabel ? $offLabel : ""; |
|
50
|
|
|
$rLabel = null !== $onLabel ? $onLabel : ""; |
|
51
|
|
|
|
|
52
|
|
|
$span = static::coreHTMLElement("span", null, ["class" => ["lever", $class]]); |
|
53
|
|
|
$input = StringHelper::replace($template, ["%attributes%", "%innerHTML%"], [StringHelper::parseArray($attributes), $span]); |
|
54
|
|
|
$label = static::coreHTMLElement("label", $lLabel . $input . $rLabel); |
|
55
|
|
|
|
|
56
|
|
|
return static::coreHTMLElement("div", $label, ["class" => "switch"]); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|