You are here

function number_allowed_values in Content Construction Kit (CCK) 5

Create an array of the allowed values for this field

4 calls to number_allowed_values()
content.devel.inc in ./content.devel.inc
Functions needed for Devel module integration.
number_field in ./number.module
Implementation of hook_field().
number_field_formatter in ./number.module
Implementation of hook_field_formatter().
number_field_settings in ./number.module
Implementation of hook_field_settings().

File

./number.module, line 355
Defines numeric field types.

Code

function number_allowed_values($field) {
  static $allowed_values;
  if ($allowed_values[$field['field_name']]) {
    return $allowed_values[$field['field_name']];
  }
  $allowed_values[$field['field_name']] = array();
  if ($field['allowed_values_php']) {
    ob_start();
    $result = eval($field['allowed_values_php']);
    if (is_array($result)) {
      $allowed_values[$field['field_name']] = $result;
    }
    ob_end_clean();
  }
  if (!$allowed_values[$field['field_name']]) {
    $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);
      list($key, $value) = explode('|', $opt);
      $allowed_values[$field['field_name']][$key] = isset($value) && $value !== '' ? $value : $key;
    }
  }
  return $allowed_values[$field['field_name']];
}