You are here

function video_embed_field_set_target in Video Embed Field 7.2

Callback for mapping. Here is where the actual mapping happens.

When the callback is invoked, $target contains the name of the field the user has decided to map to and $value contains the value of the feed item element the user has picked as a source.

1 string reference to 'video_embed_field_set_target'
video_embed_field_feeds_processor_targets_alter in ./video_embed_field.feeds.inc
Implements hook_feeds_processor_targets_alter().

File

./video_embed_field.feeds.inc, line 39
On behalf implementation of Feeds mapping API for video_embed_field.module.

Code

function video_embed_field_set_target($source, $entity, $target, $value) {
  if (empty($value)) {
    return;
  }
  if (!is_array($value)) {
    $value = array(
      $value,
    );
  }
  list($field_name, $sub_field) = explode(':', $target, 2);
  $info = field_info_field($field_name);

  // Iterate over all values.
  $field = isset($entity->{$field_name}) ? $entity->{$field_name} : array(
    LANGUAGE_NONE => array(),
  );

  // Allow for multiple mappings to the same target.
  $count = call_user_func_array('array_merge_recursive', $field[LANGUAGE_NONE]);
  $delta = count($count[$sub_field]);
  foreach ($value as $v) {
    if ($info['cardinality'] != FIELD_CARDINALITY_UNLIMITED && $info['cardinality'] <= $delta) {
      break;
    }
    if (is_scalar($v)) {
      $field[LANGUAGE_NONE][$delta][$sub_field] = $v;
      $delta++;
    }
  }
  $entity->{$field_name} = $field;
}