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\AbstractAdminBSBTwigExtension; |
15
|
|
|
use WBW\Library\Core\Utility\Argument\StringUtility; |
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 AbstractAdminBSBTwigExtension { |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Constructor. |
28
|
|
|
*/ |
29
|
|
|
protected function __construct() { |
30
|
|
|
parent::__construct(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Displays an AdminBSB switch button. |
35
|
|
|
* |
36
|
|
|
* @param string $offLabel The off label. |
37
|
|
|
* @param string $name The name. |
38
|
|
|
* @param boolean $checked Checked ? |
39
|
|
|
* @param boolean $disabled Disable ? |
40
|
|
|
* @param string $onLabel The on label. |
41
|
|
|
* @param array $attrs The attributes. |
42
|
|
|
* @param string $class The class. |
43
|
|
|
* @return string Returns the AdminBSB switch button. |
44
|
|
|
*/ |
45
|
|
|
protected function adminBSBSwitchButton($offLabel, $name, $checked, $disabled, $onLabel, array $attrs, $class) { |
46
|
|
|
|
47
|
|
|
// Initialize the template. |
48
|
|
|
$template = "<input %attributes%>%innerHTML%"; |
49
|
|
|
|
50
|
|
|
// Initialize the attributes. |
51
|
|
|
$attributes = $attrs; |
52
|
|
|
|
53
|
|
|
$attributes["name"] = $name; |
54
|
|
|
$attributes["type"] = "checkbox"; |
55
|
|
|
$attributes["checked"] = true === $checked ? "checked" : null; |
56
|
|
|
$attributes["disabled"] = true === $disabled ? "disabled" : null; |
57
|
|
|
|
58
|
|
|
// Initialize the parameters. |
59
|
|
|
$lLabel = null !== $offLabel ? $offLabel : ""; |
60
|
|
|
$rLabel = null !== $onLabel ? $onLabel : ""; |
61
|
|
|
|
62
|
|
|
$span = self::bootstrapHTMLElement("span", null, ["class" => ["lever", $class]]); |
|
|
|
|
63
|
|
|
$input = StringUtility::replace($template, ["%attributes%", "%innerHTML%"], [StringUtility::parseArray($attributes), $span]); |
64
|
|
|
$label = self::bootstrapHTMLElement("label", $lLabel . $input . $rLabel); |
|
|
|
|
65
|
|
|
|
66
|
|
|
// Return the HTML. |
67
|
|
|
return self::bootstrapHTMLElement("div", $label, ["class" => "switch"]); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.