Radio.php
3.34 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
92
93
94
95
<?php
/**
* Radio.php
*
* Radio button form field.
*
* PHP versions 5
*
* @author Alexander Schneider <alexanderschneider85@gmail.com>
* @copyright 2008-2017 Alexander Schneider
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
* @version SVN: $id$
* @link http://wordpress.org/extend/plugins/user-access-manager/
*/
/**
* @var Radio $radio
*/
use UserAccessManager\Form\Input;
use UserAccessManager\Form\Radio;
use UserAccessManager\Form\Select;
use UserAccessManager\Form\Textarea;
?>
<th scope="row"><?php echo $radio->getLabel(); ?></th>
<td>
<?php
$possibleValues = $radio->getPossibleValues();
foreach ($possibleValues as $possibleValue) {
$rawValue = $possibleValue->getValue();
$formValue = (is_bool($rawValue) === true) ?
(($rawValue === true) ? 'true' : 'false') : $rawValue;
?>
<label for="uam_<?php echo $radio->getId() . '_' . $formValue; ?>">
<input id="uam_<?php echo $radio->getId() . '_' . $formValue; ?>"
type="radio"
name="config_parameters[<?php echo $radio->getId(); ?>]"
value="<?php echo $formValue; ?>"
<?php
if ($radio->getValue() === $possibleValue->getValue()) {
echo 'checked="checked"';
}
?>
/>
<?php echo $possibleValue->getLabel(); ?>
</label>
<?php
$subElement = $possibleValue->getSubElement();
if ($subElement !== null) {
if ($subElement instanceof Input) {
?>
<input id="uam_<?php echo $subElement->getId(); ?>"
name="config_parameters[<?php echo $subElement->getId(); ?>]"
value="<?php echo $subElement->getValue(); ?>"/>
<?php
} elseif ($subElement instanceof Textarea) {
?>
<textarea id="uam_<?php echo $subElement->getId(); ?>"
style="width:100%;min-height:120px;"
name="config_parameters[<?php echo $subElement->getId(); ?>]"><?php
echo htmlentities($subElement->getValue());
?></textarea>
<?php
} elseif ($subElement instanceof Select) {
?>
<select id="uam_<?php echo $subElement->getId(); ?>"
name="config_parameters[<?php echo $subElement->getId(); ?>]">
<?php
$subPossibleValues = $subElement->getPossibleValues();
foreach ($subPossibleValues as $subPossibleValue) {
?>
<option value="<?php echo $subPossibleValue->getValue(); ?>" <?php
if ($subElement->getValue() === $subPossibleValue->getValue()) {
echo 'selected="selected"';
}
?> >
<?php echo $subPossibleValue->getLabel(); ?>
</option>
<?php
}
?>
</select>
<?php
}
}
}
?>
<br/>
<p><?php echo $radio->getDescription(); ?></p>
</td>