Elgg  Version 1.11
select.php
Go to the documentation of this file.
1 <?php
21 $vars['class'] = (array) elgg_extract('class', $vars, []);
22 $vars['class'][] = 'elgg-input-dropdown';
23 
24 $defaults = array(
25  'disabled' => false,
26  'value' => '',
27  'options_values' => array(),
28  'options' => array(),
29 );
30 
31 $vars = array_merge($defaults, $vars);
32 
33 $options_values = $vars['options_values'];
34 unset($vars['options_values']);
35 
36 $options = $vars['options'];
37 unset($vars['options']);
38 
39 $value = is_array($vars['value']) ? $vars['value'] : array($vars['value']);
40 $value = array_map('strval', $value);
41 unset($vars['value']);
42 
43 $vars['multiple'] = !empty($vars['multiple']);
44 
45 // Add trailing [] to name if multiple is enabled to allow the form to send multiple values
46 if ($vars['multiple'] && !empty($vars['name']) && is_string($vars['name'])) {
47  if (substr($vars['name'], -2) != '[]') {
48  $vars['name'] = $vars['name'] . '[]';
49  }
50 }
51 
53 
54 if ($options_values) {
55  foreach ($options_values as $opt_value => $option) {
56 
57  $option_attrs = array(
58  'value' => $opt_value,
59  'selected' => in_array((string)$opt_value, $value),
60  );
61 
62  $options_list .= elgg_format_element('option', $option_attrs, $option);
63  }
64 } else {
65  if (is_array($options)) {
66  foreach ($options as $option) {
67 
68  $option_attrs = ['selected' => in_array((string)$option, $value)];
69 
70  $options_list .= elgg_format_element('option', $option_attrs, $option);
71  }
72  }
73 }
74 
$defaults
Definition: select.php:24
$value
Definition: select.php:39
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
$options_values
Definition: select.php:33
$options
Definition: select.php:36
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:215
if($vars['multiple']&&!empty($vars['name'])&&is_string($vars['name'])) $options_list
Definition: select.php:52
elgg echo
Translates a string.
Definition: languages.js:43
$vars['class']
Definition: select.php:21