You are here

function geolocation_set_target_simple in Geolocation Field 7

Example callback specified in hook_feeds_processor_targets_alter().

Parameters

$source: Field mapper source settings.

$entity: An entity object, for instance a node object.

$target: A string identifying the target on the node.

$values: The values to populate the target with.

1 string reference to 'geolocation_set_target_simple'
geolocation_feeds_processor_targets_alter in ./geolocation.feeds.inc
Implements hook_feeds_node_processor_targets_alter().

File

./geolocation.feeds.inc, line 43
Provides integration with Feeds module (http://drupal.org/project/feeds)

Code

function geolocation_set_target_simple($source, $entity, $target, $values) {
  list($field_name, $sub_field) = explode(':', $target, 2);

  // Handle non-multiple value fields.
  if (!is_array($values)) {
    $values = array(
      $values,
    );
  }

  // If the field is already set on the given entity, update the existing value
  // array. Otherwise start with a fresh field value array.
  $field = isset($entity->{$field_name}) ? $entity->{$field_name} : array();

  // Loop over the field values array...
  foreach ($values as $delta => $value) {
    $field[LANGUAGE_NONE][$delta][$sub_field] = $value;
  }
  $entity->{$field_name} = $field;
}