You are here

function content_allowed_values in Content Construction Kit (CCK) 6

Same name and namespace in other branches
  1. 6.3 content.module \content_allowed_values()
  2. 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.

11 calls to content_allowed_values()
number_field in modules/number/number.module
Implementation of hook_field().
number_field_settings in modules/number/number.module
Implementation of hook_field_settings().
optionwidgets_options in modules/optionwidgets/optionwidgets.module
Helper function for finding the allowed values list for a field.
text_field in examples/example_field.php
Implementation of hook_field().
text_field in modules/text/text.module
Implementation of hook_field().

... See full list

File

./content.module, line 1456
Allows administrators to associate custom fields to content types.

Code

function content_allowed_values($field) {
  static $allowed_values;
  if (isset($allowed_values[$field['field_name']])) {
    return $allowed_values[$field['field_name']];
  }
  $allowed_values[$field['field_name']] = array();
  if (isset($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 (empty($allowed_values[$field['field_name']]) && isset($field['allowed_values'])) {
    $list = explode("\n", $field['allowed_values']);
    $list = array_map('trim', $list);
    $list = array_filter($list, 'strlen');
    foreach ($list as $opt) {
      if (strpos($opt, '|') !== FALSE) {
        list($key, $value) = explode('|', $opt);
        $allowed_values[$field['field_name']][$key] = $value ? $value : $key;
      }
      else {
        $allowed_values[$field['field_name']][$opt] = $opt;
      }
    }
  }
  return $allowed_values[$field['field_name']];
}