You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

83 lines
2.5 KiB

  1. <?php
  2. /**
  3. * Class helper_plugin_bureaucracy_fieldselect
  4. *
  5. * Creates a dropdown list
  6. */
  7. class helper_plugin_bureaucracy_fieldradio extends helper_plugin_bureaucracy_field {
  8. protected $mandatory_args = 3;
  9. /**
  10. * Arguments:
  11. * - cmd
  12. * - label
  13. * - option1|option2|etc
  14. * - ^ (optional)
  15. *
  16. * @param array $args The tokenized definition, only split at spaces
  17. */
  18. public function initialize($args) {
  19. $this->init($args);
  20. $this->opt['args'] = array_filter(array_map('trim', explode('|',array_shift($args))));
  21. $this->standardArgs($args);
  22. }
  23. /**
  24. * Render the field as XHTML
  25. *
  26. * Outputs the represented field using the passed Doku_Form object.
  27. * Additional parameters (CSS class & HTML name) are passed in $params.
  28. *
  29. * @params array $params Additional HTML specific parameters
  30. * @params Doku_Form $form The target Doku_Form object
  31. * @params int $formid unique identifier of the form which contains this field
  32. */
  33. public function renderfield($params, Doku_Form $form, $formid) {
  34. $this->_handlePreload();
  35. if(!$form->_infieldset){
  36. $form->startFieldset('');
  37. }
  38. if ($this->error) {
  39. $params['class'] = 'bureaucracy_error';
  40. }
  41. $params = array_merge($this->opt, $params);
  42. list($name, $entries, $value, $label, $id, $class) = $this->_parse_tpl(
  43. array(
  44. '@@NAME@@',
  45. $params['args'],
  46. '@@VALUE@@',
  47. '@@DISPLAY@@',
  48. '@@ID@@',
  49. '@@CLASS@@'
  50. ),
  51. $params
  52. );
  53. $value = (in_array($value, $entries) ? $value : null);
  54. $valueoffieldwithid = ($value !== null ? $value : current($entries));
  55. // label
  56. $s = '<label';
  57. $s .= ' class="radiolabel '.$class.'"';
  58. $s .= '><span>' . $label . '</span>';
  59. $s .= '</label>';
  60. $form->addElement($s);
  61. // radio fields
  62. foreach($entries as $val) {
  63. if($value === $val) {
  64. $attrs = array('checked' => 'checked');
  65. } else {
  66. $attrs = array();
  67. }
  68. if($valueoffieldwithid === $val) {
  69. $_id = $id; //e.g. autofocus with 'focus__this' id
  70. } else {
  71. $_id = '';
  72. }
  73. $form->addElement(form_makeRadioField($name, $val, $val, $_id, $class, $attrs));
  74. }
  75. }
  76. }