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
|
<?php
/**
* Class helper_plugin_bureaucracy_fieldselect
*
* Creates a dropdown list
*/
class helper_plugin_bureaucracy_fieldradio extends helper_plugin_bureaucracy_field {
protected $mandatory_args = 3;
/**
* Arguments:
* - cmd
* - label
* - option1|option2|etc
* - ^ (optional)
*
* @param array $args The tokenized definition, only split at spaces
*/
public function initialize($args) {
$this->init($args);
$this->opt['args'] = array_filter(array_map('trim', explode('|',array_shift($args))));
$this->standardArgs($args);
}
/**
* Render the field as XHTML
*
* Outputs the represented field using the passed Doku_Form object.
* Additional parameters (CSS class & HTML name) are passed in $params.
*
* @params array $params Additional HTML specific parameters
* @params Doku_Form $form The target Doku_Form object
* @params int $formid unique identifier of the form which contains this field
*/
public function renderfield($params, Doku_Form $form, $formid) {
$this->_handlePreload();
if(!$form->_infieldset){
$form->startFieldset('');
}
if ($this->error) {
$params['class'] = 'bureaucracy_error';
}
$params = array_merge($this->opt, $params);
list($name, $entries, $value, $label, $id, $class) = $this->_parse_tpl(
array(
'@@NAME@@',
$params['args'],
'@@VALUE@@',
'@@DISPLAY@@',
'@@ID@@',
'@@CLASS@@'
),
$params
);
$value = (in_array($value, $entries) ? $value : null);
$valueoffieldwithid = ($value !== null ? $value : current($entries));
// label
$s = '<label';
$s .= ' class="radiolabel '.$class.'"';
$s .= '><span>' . $label . '</span>';
$s .= '</label>';
$form->addElement($s);
// radio fields
foreach($entries as $val) {
if($value === $val) {
$attrs = array('checked' => 'checked');
} else {
$attrs = array();
}
if($valueoffieldwithid === $val) {
$_id = $id; //e.g. autofocus with 'focus__this' id
} else {
$_id = '';
}
$form->addElement(form_makeRadioField($name, $val, $val, $_id, $class, $attrs));
}
}
}
|