You are here

function emfield_feeds_set_target in Feeds 6

Same name and namespace in other branches
  1. 7 mappers/emfield.inc \emfield_feeds_set_target()

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 'emfield_feeds_set_target'
emfield_feeds_node_processor_targets_alter in mappers/emfield.inc
Implementation of hook_feeds_node_processor_targets_alter().

File

mappers/emfield.inc, line 40
On behalf implementation of Feeds mapping API for emfield.module (Embedded Media Field).

Code

function emfield_feeds_set_target(&$node, $target, $value) {
  $field = isset($node->{$target}) ? $node->{$target} : array();

  // Handle non-multiple value fields.
  if (!is_array($value)) {
    $value = array(
      $value,
    );
  }
  $i = 0;
  foreach ($value as $v) {
    if ($v instanceof FeedsElement) {
      $field[$i]['embed'] = (string) $v;
      $i++;
    }
    elseif (!is_array($v) && !is_object($v)) {
      $field[$i]['embed'] = $v;
      $i++;
    }
  }
  $node->{$target} = $field;
}