You are here

function text_feeds_set_target in Feeds 8.2

Same name and namespace in other branches
  1. 7.2 mappers/text.inc \text_feeds_set_target()

Callback for mapping text fields.

1 string reference to 'text_feeds_set_target'
text_feeds_processor_targets_alter in mappers/text.inc
Implements hook_feeds_processor_targets_alter().

File

mappers/text.inc, line 36
On behalf implementation of Feeds mapping API for text.module.

Code

function text_feeds_set_target($source, $entity, $target, $value) {
  if (empty($value)) {
    return;
  }
  if (!is_array($value)) {
    $value = array(
      $value,
    );
  }
  if (isset($source->importer->processor->config['input_format'])) {
    $format = $source->importer->processor->config['input_format'];
  }
  $info = field_info_field($target);

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

  // Allow for multiple mappings to the same target.
  $delta = count($field['und']);
  foreach ($value as $v) {
    if ($info['cardinality'] == $delta) {
      break;
    }
    if (is_object($v) && $v instanceof FeedsElement) {
      $v = $v
        ->getValue();
    }
    if (is_scalar($v)) {
      $field['und'][$delta]['value'] = $v;
      if (isset($format)) {
        $field['und'][$delta]['format'] = $format;
      }
      $delta++;
    }
  }
  $entity->{$target} = $field;
}