You are here

function text_allowed_values in Content Construction Kit (CCK) 5

Create an array of the allowed values for this field

5 calls to text_allowed_values()
content.devel.inc in ./content.devel.inc
Functions needed for Devel module integration.
hook_field in ./field.php
Define the behavior of a field type.
text_field in ./text.module
Implementation of hook_field().
text_field_formatter in ./text.module
Implementation of hook_field_formatter().
text_field_settings in ./text.module
Implementation of hook_field_settings().

File

./text.module, line 399
Defines simple text field types.

Code

function text_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']];
}