Elgg  Version 2.3
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 = elgg_extract_class($vars, ['elgg-input-radios', "elgg-{$vars['align']}"]);
43 
44 unset($vars['class']);
45 unset($vars['align']);
46 
47 $vars['class'] = 'elgg-input-radio';
48 
49 if (is_array($vars['value'])) {
50  $vars['value'] = array_map('elgg_strtolower', $vars['value']);
51 } else {
52  $vars['value'] = array(elgg_strtolower($vars['value']));
53 }
54 
55 $value = $vars['value'];
56 unset($vars['value']);
57 
58 $radios = '';
59 foreach ($options as $label => $option) {
60 
61  $vars['checked'] = in_array(elgg_strtolower($option), $value);
62  $vars['value'] = $option;
63 
64  $radio = elgg_format_element('input', $vars);
65  $radios .= "<li><label>{$radio}{$label}</label></li>";
66 }
67 
68 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_extract_class(array $array, $existing=[])
Extract class names from an array with key "class", optionally merging into a preexisting set...
Definition: elgglib.php:1396
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:208
if(empty($options)) $id
Definition: radio.php:39
$value
Definition: radio.php:55
$vars
Definition: radio.php:30
elgg echo
Translates a string.
Definition: languages.js:48
$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:1375
$list_class
Definition: radio.php:42
$radios
Definition: radio.php:58
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7