-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathCheckbox.php
More file actions
91 lines (82 loc) · 2.25 KB
/
Checkbox.php
File metadata and controls
91 lines (82 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace dokuwiki\plugin\struct\types;
class Checkbox extends AbstractBaseType
{
protected $config = ['values' => 'one, two, three'];
/**
* Creates the options array
*
* @return array
*/
public function getOptions()
{
$options = explode(',', $this->config['values']);
$options = array_map('trim', $options);
$options = array_filter($options);
return $options;
}
/**
* A single checkbox, additional values are ignored
*
* @param string $name
* @param string $rawvalue
* @param string $htmlID
*
* @return string
*/
public function valueEditor($name, $rawvalue, $htmlID)
{
$options = $this->getOptions();
$opt = array_shift($options);
if ($rawvalue == $opt) {
$checked = 'checked';
} else {
$checked = '';
}
$opt = hsc($opt);
$params = [
'name' => $name,
'value' => $opt,
'class' => 'struct_' . strtolower($this->getClass()),
'type' => 'checkbox',
'id' => $htmlID,
'checked' => $checked
];
$attributes = buildAttributes($params, true);
return "<label><input $attributes> $opt</label>";
}
/**
* Multiple checkboxes
*
* @param string $name
* @param \string[] $rawvalues
* @param string $htmlID
*
* @return string
*/
public function multiValueEditor($name, $rawvalues, $htmlID)
{
$class = 'struct_' . strtolower($this->getClass());
$html = '';
foreach ($this->getOptions() as $opt) {
if (in_array($opt, $rawvalues)) {
$checked = 'checked';
} else {
$checked = '';
}
$params = [
'name' => $name . '[]',
'value' => $opt,
'class' => $class,
'type' => 'checkbox',
'id' => $htmlID,
'checked' => $checked
];
$attributes = buildAttributes($params, true);
$htmlID = '';
$opt = hsc($opt);
$html .= "<label><input $attributes> $opt</label>";
}
return $html;
}
}