You are here

function name_feeds_set_target in Name Field 7

Callback for feed mapping.

1 string reference to 'name_feeds_set_target'
name_feeds_processor_targets_alter in ./name.feeds.inc
Implements hook_feeds_processor_targets_alter().

File

./name.feeds.inc, line 31
Implements Feeds mapping API.

Code

function name_feeds_set_target($source, $entity, $target, $value) {
  if (empty($value)) {
    return;
  }

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

  // Iterate over all values.
  $i = 0;
  $info = field_info_field($target);
  list($field_name, $sub_field) = explode(':', $target);

  // We will call this multiple times, preserve existing values.
  $field = empty($entity->{$field_name}) ? array() : $entity->{$field_name};
  foreach ($value as $v) {
    if (!is_array($v) && !is_object($v)) {
      $field[LANGUAGE_NONE][$i][$sub_field] = $v;
    }
    if ($info['cardinality'] == 1) {
      break;
    }
    $i++;
  }
  $entity->{$field_name} = $field;
}