You are here

function number_feeds_set_target in Feeds 8.2

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

Callback for mapping numerics.

Ensure that $value is a numeric to avoid database errors.

1 string reference to 'number_feeds_set_target'
number_feeds_processor_targets_alter in mappers/number.inc
Implements hook_feeds_processor_targets_alter().

File

mappers/number.inc, line 40
On behalf implementation of Feeds mapping API for number.module.

Code

function number_feeds_set_target($source, $entity, $target, $value) {

  // Do not perform the regular empty() check here. 0 is a valid value. That's
  // really just a performance thing anyway.
  if (!is_array($value)) {
    $value = array(
      $value,
    );
  }
  $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_numeric($v)) {
      $field['und'][$delta]['value'] = $v;
      $delta++;
    }
  }
  $entity->{$target} = $field;
}