Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
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  $radio = elgg_format_element('input', $vars);
67  $radios .= "<li><label>{$radio}{$label}</label></li>";
68 }
69 
70 echo elgg_format_element('ul', ['class' => $list_class, 'id' => $id], $radios);
$options
Definition: radio.php:32
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:218
if(empty($options)) $id
Definition: radio.php:39
$value
Definition: radio.php:57
$vars
Definition: radio.php:30
$defaults
Definition: radio.php:21
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1310
$list_class
Definition: radio.php:42
$radios
Definition: radio.php:60
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7