You are here

function global_filter_get_field_value_key in Views Global Filter 7

Same name and namespace in other branches
  1. 8 global_filter.module \global_filter_get_field_value_key()

Utility function to convert a list field value to its associated key.

Parameters

object $field: field object as obtained via field_info_field($field_name).

string $value: e.g., '$100 - $200'

Return value

string key, e.g., 'medium' or 3

1 call to global_filter_get_field_value_key()
global_filter_plugin_argument_default_global_filter_field::get_argument in views/global_filter_plugin_argument_default_global_filter_field.inc
Get argument.

File

./global_filter.module, line 541
global_filter.module

Code

function global_filter_get_field_value_key($field, $value) {
  if (!empty($field['settings'])) {
    $function = $field['settings']['allowed_values_function'];
    if (!empty($function) && function_exists($function)) {
      $values = $function($field);
    }
    else {
      $values = $field['settings']['allowed_values'];
    }
    if (!empty($values)) {
      foreach ($values as $key => $val) {
        if ($val == $value) {
          return $key;
        }
      }
    }
  }

  // Key not found, return original argument.
  return $value;
}