You are here

function conditional_fields_allowed_values in Conditional Fields 5

Same name and namespace in other branches
  1. 6.2 conditional_fields.module \conditional_fields_allowed_values()

Create an array of the allowed values for a field

2 calls to conditional_fields_allowed_values()
conditional_fields_content_admin_field in ./conditional_fields.module
Alteration of the field editing form
conditional_fields_fieldgroup_edit_group_form in ./conditional_fields.module
Alteration of the fieldgroup editing form

File

./conditional_fields.module, line 838

Code

function conditional_fields_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) {
      list($key, $value) = explode('|', $opt);
      $allowed_values[$field['field_name']][$key] = $value ? $value : $key;
    }
  }
  return $allowed_values[$field['field_name']];
}