You are here

function link_feeds_set_target in Feeds 8.2

Same name and namespace in other branches
  1. 6 mappers/link.inc \link_feeds_set_target()
  2. 7.2 mappers/link.inc \link_feeds_set_target()
  3. 7 mappers/link.inc \link_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 'link_feeds_set_target'
link_feeds_processor_targets_alter in mappers/link.inc
Implements hook_feeds_processor_targets_alter().

File

mappers/link.inc, line 44
On behalf implementation of Feeds mapping API for link.module.

Code

function link_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.
  list($field_name, $column) = explode(':', $target);
  $info = field_info_field($field_name);
  $field = isset($entity->{$field_name}) ? $entity->{$field_name} : array();
  $delta = 0;
  foreach ($value as $v) {
    if ($info['cardinality'] == $delta) {
      break;
    }
    if (is_object($v) && $v instanceof FeedsElement) {
      $v = $v
        ->getValue();
    }
    if (is_scalar($v)) {
      if (!isset($field['und'][$delta]['title'])) {
        $field['und'][$delta]['title'] = '';
      }
      if (!isset($field['und'][$delta]['url'])) {
        $field['und'][$delta]['url'] = '';
      }
      $field['und'][$delta][$column] = $v;
      $delta++;
    }
  }
  $entity->{$field_name} = $field;
}