You are here

function _geofield_set_target in Geofield 7

Same name and namespace in other branches
  1. 7.2 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.

$value: 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 192
Provides integration with Feeds module (http://drupal.org/project/feeds)

Code

function _geofield_set_target($source, $entity, $target, $value) {
  if (empty($value)) {
    return;
  }
  $info = field_info_field($target);

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

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