|
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 checkbox Twig extension. |
|
19
|
|
|
* |
|
20
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
21
|
|
|
* @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Form |
|
22
|
|
|
* @abstract |
|
23
|
|
|
*/ |
|
24
|
|
|
abstract class AbstractCheckboxTwigExtension extends AbstractTwigExtension { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Displays a AdminBSB checkbox. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $content The content. |
|
30
|
|
|
* @param string $name The name. |
|
31
|
|
|
* @param string $id The id. |
|
32
|
|
|
* @param bool $checked Checked ? |
|
33
|
|
|
* @param bool $disabled Disabled ? |
|
34
|
|
|
* @param bool $filledIn Filled in ? |
|
35
|
|
|
* @param string $class The class. |
|
36
|
|
|
* @return string Returns the AdminBSB checkbox. |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function adminBSBCheckbox($content, $name, $id, $checked, $disabled, $filledIn, $class) { |
|
39
|
|
|
|
|
40
|
|
|
$template = "<input %attributes%>%innerHTML%"; |
|
41
|
|
|
|
|
42
|
|
|
$attributes = []; |
|
43
|
|
|
|
|
44
|
|
|
$attributes["class"] = [true === $filledIn ? "filled-in" : null, $class]; |
|
45
|
|
|
$attributes["name"] = $name; |
|
46
|
|
|
$attributes["type"] = "checkbox"; |
|
47
|
|
|
$attributes["id"] = $id; |
|
48
|
|
|
$attributes["checked"] = true === $checked ? "checked" : null; |
|
49
|
|
|
$attributes["disabled"] = true === $disabled ? "disabled" : null; |
|
50
|
|
|
|
|
51
|
|
|
$innerHTML = static::coreHTMLElement("label", $content, ["for" => $attributes["id"]]); |
|
52
|
|
|
|
|
53
|
|
|
return StringHelper::replace($template, ["%attributes%", "%innerHTML%"], [StringHelper::parseArray($attributes), $innerHTML]); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|