You are here

function views_tree_normalize_key in Views tree 7.2

Normalize a value out of the record to an int.

If the field in question comes from Field API, then it will be an array, not an int. We need to detect that and extract the int value we want from it. Note that because Field API structures are so free-form, we have to specifically support each field type. For now we support entityreference (target_id), nodereference (nid), userreference (uid), organic groups (gid), and taxonomyreference (tid).

Parameters

mixed $value: The value to normalize. It should be either an int or an array. If an int, it is returned unaltered. If it's an array, we extract the int we want and return that.

views_handler_field $field: Metadata about the field we are extracting information from.

Return value

int The value of this key, normalized to an int.

1 call to views_tree_normalize_key()
theme_views_tree in ./views_tree.module
Theme function for the tree style plugin.

File

./views_tree.module, line 172
Views Tree module.

Code

function views_tree_normalize_key($value, views_handler_field $field) {
  if (is_array($value) && count($value)) {
    if (isset($field->field_info['columns'])) {
      $columns = array_keys($field->field_info['columns']);
      foreach ($columns as $column) {
        if (in_array($column, array(
          'target_id',
          'nid',
          'uid',
          'tid',
        ))) {
          $field_property = $column;
          break;
        }
      }
    }
    else {
      $field_property = '';
    }
    return $field_property ? $value[0][$field_property] : 0;
  }
  else {
    return $value ? $value : 0;
  }
}