Elgg  Version 1.11
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  'type' => 'radio'
28 );
29 
30 $vars = array_merge($defaults, $vars);
31 
32 $options = elgg_extract('options', $vars);
33 unset($vars['options']);
34 
35 if (empty($options)) {
36  return;
37 }
38 
39 $id = elgg_extract('id', $vars, '');
40 unset($vars['id']);
41 
42 $list_class = (array) elgg_extract('class', $vars, []);
43 $list_class[] = 'elgg-input-radios';
44 $list_class[] = "elgg-{$vars['align']}";
45 
46 unset($vars['class']);
47 unset($vars['align']);
48 
49 $vars['class'] = 'elgg-input-radio';
50 
51 if (is_array($vars['value'])) {
52  $vars['value'] = array_map('elgg_strtolower', $vars['value']);
53 } else {
54  $vars['value'] = array(elgg_strtolower($vars['value']));
55 }
56 
57 $value = $vars['value'];
58 unset($vars['value']);
59 
60 $radios = '';
61 foreach ($options as $label => $option) {
62 
63  $vars['checked'] = in_array(elgg_strtolower($option), $value);
64  $vars['value'] = $option;
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  $radio = elgg_format_element('input', $vars);
73  $radios .= "<li><label>{$radio}{$label}</label></li>";
74 }
75 
76 echo elgg_format_element('ul', ['class' => $list_class, 'id' => $id], $radios);
$options
Definition: radio.php:32
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1246
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:174
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:215
if(empty($options)) $id
Definition: radio.php:39
$value
Definition: radio.php:57
$vars
Definition: radio.php:30
elgg echo
Translates a string.
Definition: languages.js:43
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1006
$defaults
Definition: radio.php:21
$list_class
Definition: radio.php:42
$radios
Definition: radio.php:60
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7