| 1 |
<?php |
<?php |
| 2 |
//$Id: valuelist.module,v 1.4 2008/02/28 14:11:02 usonian Exp $ |
//$Id: valuelist.module 1820 2008-07-24 19:49:42Z andy $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 210 |
* |
* |
| 211 |
* @param string $vl_name |
* @param string $vl_name |
| 212 |
* The name of the value list being retrieved. |
* The name of the value list being retrieved. |
| 213 |
|
* @param boolean $allow_empty |
| 214 |
|
* Whether or not to include an empty value at the top of the list; useful if a select menu |
| 215 |
|
* generated from this value list isn't required, or if you don't want it to default to the |
| 216 |
|
* first item in the list when lazy people skip it. |
| 217 |
|
* @param string $empty_label |
| 218 |
|
* If $allow_empty is true, use this string as the label which will appear as the top, empty item in the option list. |
| 219 |
* @return array |
* @return array |
| 220 |
*/ |
*/ |
| 221 |
function valuelist_get_array($vl_name) { |
function valuelist_get_array($vl_name, $allow_empty = FALSE, $empty_label = '-----') { |
| 222 |
$options = array(); |
$options = array(); |
| 223 |
$list = variable_get(_valuelist_sys_list_name($vl_name), array()); |
$list = variable_get(_valuelist_sys_list_name($vl_name), array()); |
| 224 |
$lines = explode("\n", $list); |
$lines = explode("\n", $list); |
| 225 |
|
|
| 226 |
|
if ($allow_empty) { |
| 227 |
|
$lines = array_reverse($lines); |
| 228 |
|
$lines[] = '|'. $empty_label; |
| 229 |
|
$lines = array_reverse($lines); |
| 230 |
|
} |
| 231 |
|
|
| 232 |
foreach ($lines as $line) { |
foreach ($lines as $line) { |
| 233 |
if (strpos($line, '|')) { |
if (strpos($line, '|') === FALSE) {//Check specifically for boolean false; a strpos index of 0 is a true result in this case |
| 234 |
|
$value = trim($line); |
| 235 |
|
$label = trim($line); |
| 236 |
|
} |
| 237 |
|
else{ |
| 238 |
$parts = explode('|', $line); |
$parts = explode('|', $line); |
| 239 |
$value = trim($parts[0]); |
$value = trim($parts[0]); |
| 240 |
$label = trim($parts[1]); |
$label = trim($parts[1]); |
| 241 |
} |
} |
|
else{ |
|
|
$value = trim($line); |
|
|
$label = trim($line); |
|
|
} |
|
| 242 |
$options[$value] = t($label); |
$options[$value] = t($label); |
| 243 |
} |
} |
| 244 |
|
|