Elgg  Version 1.9
radio.php
Go to the documentation of this file.
1 <?php
21 $defaults = array(
22  'align' => 'vertical',
23  'value' => array(),
24  'disabled' => false,
25  'options' => array(),
26  'name' => '',
27 );
28 
29 $vars = array_merge($defaults, $vars);
30 
31 $id = '';
32 if (isset($vars['id'])) {
33  $id = "id=\"{$vars['id']}\"";
34  unset($vars['id']);
35 }
36 
37 $class = "elgg-input-radios elgg-{$vars['align']}";
38 if (isset($vars['class'])) {
39  $class .= " {$vars['class']}";
40  unset($vars['class']);
41 }
42 unset($vars['align']);
43 $vars['class'] = 'elgg-input-radio';
44 
45 if (is_array($vars['value'])) {
46  $vars['value'] = array_map('elgg_strtolower', $vars['value']);
47 } else {
48  $vars['value'] = array(elgg_strtolower($vars['value']));
49 }
50 
51 $options = $vars['options'];
52 unset($vars['options']);
53 
54 $value = $vars['value'];
55 unset($vars['value']);
56 
57 if ($options && count($options) > 0) {
58  echo "<ul class=\"$class\" $id>";
59  foreach ($options as $label => $option) {
60 
61  $vars['checked'] = in_array(elgg_strtolower($option), $value);
62  $vars['value'] = $option;
63 
65 
66  // handle indexed array where label is not specified
67  // @deprecated 1.8 Remove in 1.9
68  if (is_integer($label)) {
69  elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/radio', 1.8);
70  $label = $option;
71  }
72 
73  echo "<li><label><input type=\"radio\" $attributes />$label</label></li>";
74  }
75  echo '</ul>';
76 }
$options
Definition: radio.php:51
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:178
$value
Definition: radio.php:54
$vars
Definition: radio.php:29
elgg echo
Translates a string.
Definition: languages.js:43
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
elgg_format_attributes(array $attrs=array())
Converts an associative array into a string of well-formed attributes.
Definition: output.php:118
$defaults
Definition: radio.php:21
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7
if(isset($vars['id'])) $class
Definition: radio.php:37
$id
Definition: radio.php:31
$attributes
Definition: ajax_loader.php:13