Completed
Push — master ( 8d8bfa...591466 )
by WEBEWEB
14:10
created

AbstractFormTwigExtension::adminBSBRadioButton()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
c 0
b 0
f 0
rs 8.7624
cc 5
eloc 11
nc 16
nop 7
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\AbstractABSBMDTwigExtension;
15
use WBW\Library\Core\Utility\Argument\StringUtility;
16
17
/**
18
 * Abstract form Twig extension.
19
 *
20
 * @author webeweb <https://github.com/webeweb/>
21
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension\Form
22
 * @abstract
23
 */
24
abstract class AbstractFormTwigExtension extends AbstractABSBMDTwigExtension {
25
26
    /**
27
     * Constructor.
28
     */
29
    public function __construct() {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Displays a AdminBSB checkbox.
35
     *
36
     * @param string $content The checkbox content.
37
     * @param string $name The checkbox name.
38
     * @param string $id The checkbox id.
39
     * @param boolean $checked Checked ?
40
     * @param boolean $disabled Disabled ?
41
     * @param boolean $filledIn Filled in ?
42
     * @param string $class The checkbox class.
43
     * @return string Returns the AdminBSB checkbox.
44
     */
45
    final protected function adminBSBCheckbox($content, $name, $id, $checked, $disabled, $filledIn, $class) {
46
47
        // Initialize the template.
48
        $template = '<input %attributes%><label for="%id%">%innerHTML%</label>';
49
50
        // Initialize the attributes.
51
        $attributes = [];
52
53
        $attributes["class"]    = [true === $filledIn ? "filled-in" : null, $class];
54
        $attributes["name"]     = $name;
55
        $attributes["type"]     = "checkbox";
56
        $attributes["id"]       = $id;
57
        $attributes["checked"]  = true === $checked ? "checked" : null;
58
        $attributes["disabled"] = true === $disabled ? "disabled" : null;
59
60
        // Check the parameters.
61
        $innerHTML = null !== $content ? $content : "";
62
63
        // Return the HTML.
64
        return StringUtility::replace($template, ["%attributes%", "%id%", "%innerHTML%"], [StringUtility::parseArray($attributes), $attributes["id"], $innerHTML]);
65
    }
66
67
    /**
68
     * Displays a AdminBSB radio button.
69
     *
70
     * @param string $content The radio button content.
71
     * @param string $name The radio button name.
72
     * @param string $id The radio button id.
73
     * @param boolean $checked Checked ?
74
     * @param boolean $disabled Disabled ?
75
     * @param boolean $withGap With gap ?
76
     * @param string $class The radio button class.
77
     * @return string Returns the AdminBSB radio button.
78
     */
79
    final protected function adminBSBRadioButton($content, $name, $id, $checked, $disabled, $withGap, $class) {
80
81
        // Initialize the template.
82
        $template = '<input %attributes%><label for="%id%">%innerHTML%</label>';
83
84
        // Initialize the attributes.
85
        $attributes = [];
86
87
        $attributes["class"]    = [true === $withGap ? "with-gap" : null, $class];
88
        $attributes["name"]     = $name;
89
        $attributes["type"]     = "radio";
90
        $attributes["id"]       = $id;
91
        $attributes["checked"]  = true === $checked ? "checked" : null;
92
        $attributes["disabled"] = true === $disabled ? "disabled" : null;
93
94
        // Check the parameters.
95
        $innerHTML = null !== $content ? $content : "";
96
97
        // Return the HTML.
98
        return StringUtility::replace($template, ["%attributes%", "%id%", "%innerHTML%"], [StringUtility::parseArray($attributes), $attributes["id"], $innerHTML]);
99
    }
100
101
    /**
102
     * Displays an AdminBSB switch button.
103
     *
104
     * @param string $offLabel The switch button off label.
105
     * @param string $name The switch button name.
106
     * @param boolean $checked Checked switch button ?
107
     * @param boolean $disabled Disable switch button ?
108
     * @param string $onLabel The switch button on label.
109
     * @param array $attrs The switch button attributes.
110
     * @param string $class The switch button class.
111
     * @return string Returns the AdminBSB switch button.
112
     */
113
    final protected function adminBSBSwitchButton($offLabel, $name, $checked, $disabled, $onLabel, array $attrs, $class = null) {
114
115
        // Initialize the template.
116
        $template = '<div class="switch"><label>%lLabel%<input %attributes%><span class="lever%sClass%"></span>%rLabel%</label></div>';
117
118
        // Initialize the attributes.
119
        $attributes = $attrs;
120
121
        $attributes["name"]     = $name;
122
        $attributes["type"]     = "checkbox";
123
        $attributes["checked"]  = true === $checked ? "checked" : null;
124
        $attributes["disabled"] = true === $disabled ? "disabled" : null;
125
126
        // Check the parameters.
127
        $lLabel = null !== $offLabel ? $offLabel : "";
128
        $sClass = null !== $class ? " " . trim($class) : "";
129
        $rLabel = null !== $onLabel ? $onLabel : "";
130
131
        // Return the HTML.
132
        return StringUtility::replace($template, ["%lLabel%", "%attributes%", "%sClass%", "%rLabel%"], [$lLabel, StringUtility::parseArray($attributes), $sClass, $rLabel]);
133
    }
134
135
}
136