You are here

function fivestar_field_target in Fivestar 6

Same name and namespace in other branches
  1. 5 fivestar_field.inc \fivestar_field_target()
  2. 6.2 includes/fivestar.field.inc \fivestar_field_target()

Helper function to find the nid that should be rated when a field is changed.

1 call to fivestar_field_target()
fivestar_field in ./fivestar_field.inc
Implementation of hook_field().

File

./fivestar_field.inc, line 138
Provides CCK integration for fivestar module

Code

function fivestar_field_target($node, $field, $item) {
  $target = FALSE;
  if (!empty($field['php_target'])) {

    // Use eval rather than drupal_eval to allow access to local variables.
    $target = eval($field['php_target']);
  }
  elseif ($field['dynamic_target'] && !empty($node->{$field}['dynamic_target'])) {
    if (is_array($node->{$field}['dynamic_target']) && is_numeric($node->{$field['dynamic_target']}[0]['nid'])) {
      $target = $node->{$field['dynamic_target']}[0]['nid'];
    }
    elseif (is_numeric($node->{$field}['dynamic_target'])) {
      $target = $node->{$field}['dynamic_target'];
    }
  }
  elseif (isset($item['target'][0]['nid'])) {
    $target = $item['target'][0]['nid'];
  }
  return $target;
}