You are here

function _geofield_set_target in Geofield 7.2

Same name and namespace in other branches
  1. 7 geofield.feeds.inc \_geofield_set_target()

Helper function to set values and respect ordinality of field.

Based on _field_feeds_set_target(). But type set, more keys than just value.

Parameters

$source: A FeedsSource object.

$entity: The entity to map to.

$target: The target key on $entity to map to.

$values: The value to map. MUST be an array.

2 calls to _geofield_set_target()
geofield_set_target_combined in ./geofield.feeds.inc
Feeds processor target callback from the already combined source.
geofield_set_target_wkt in ./geofield.feeds.inc
Feeds processor target callback for WKT source.

File

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

Code

function _geofield_set_target($source, $entity, $target, $values) {
  if (empty($values)) {
    return;
  }

  // Iterate over all values.
  $i = 0;
  $field = isset($entity->{$target}) ? $entity->{$target} : array(
    'und' => array(),
  );
  foreach ($values as $value) {

    // Check if field value is empty.
    if (empty($value)) {
      continue;
    }
    if (is_array($value) || is_object($value)) {
      $field['und'][$i] = $value;
    }
    $i++;
  }
  $entity->{$target} = $field;
}