function content_allowed_values in Content Construction Kit (CCK) 6.3
Same name and namespace in other branches
- 6 content.module \content_allowed_values()
- 6.2 content.module \content_allowed_values()
Create an array of the allowed values for this field.
Used by number and text fields, expects to find either PHP code that will return the correct value, or a string with keys and labels separated with '|' and with each new value on its own line.
Parameters
$field: The field whose allowed values are requested.
$flatten: Optional. Use TRUE to return a flattened array (default). FALSE can be used to support optgroups for select widgets when allowed values list is generated using PHP code.
10 calls to content_allowed_values()
- content.devel.inc in includes/
content.devel.inc - Functions needed for Devel module integration.
- content_handler_argument_many_to_one::allowed_values in includes/
views/ handlers/ content_handler_argument_many_to_one.inc - content_handler_filter_many_to_one::allowed_values in includes/
views/ handlers/ content_handler_filter_many_to_one.inc - number_field in modules/
number/ number.module - Implementation of hook_field().
- number_field_settings in modules/
number/ number.module - Implementation of hook_field_settings().
File
- ./
content.module, line 1749 - Allows administrators to associate custom fields to content types.
Code
function content_allowed_values($field, $flatten = TRUE) {
static $allowed_values;
$cid = $field['field_name'] . ':' . ($flatten ? '1' : '0');
if (isset($allowed_values[$cid])) {
return $allowed_values[$cid];
}
$allowed_values[$cid] = array();
if (isset($field['allowed_values_php'])) {
ob_start();
$result = eval($field['allowed_values_php']);
if (is_array($result)) {
if ($flatten) {
$result = content_array_flatten($result);
}
$allowed_values[$cid] = $result;
}
ob_end_clean();
}
if (empty($allowed_values[$cid]) && isset($field['allowed_values'])) {
$list = explode("\n", $field['allowed_values']);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
foreach ($list as $opt) {
// Sanitize the user input with a permissive filter.
$opt = content_filter_xss($opt);
if (strpos($opt, '|') !== FALSE) {
list($key, $value) = explode('|', $opt);
$allowed_values[$cid][$key] = isset($value) && $value !== '' ? $value : $key;
}
else {
$allowed_values[$cid][$opt] = $opt;
}
}
// Allow external modules to translate allowed values list.
drupal_alter('content_allowed_values', $allowed_values[$cid], $field);
}
return $allowed_values[$cid];
}