You are here

function commerce_file_set_schema_target in Commerce File 7

Schema field target callback for hook_feeds_processor_targets_alter().

Parameters

$source: Field mapper source settings.

$entity: An entity object, for instance a node object.

$target: A string identifying the target on the entity.

$value: The value to populate the target with.

File

./commerce_file.feeds.inc, line 200
Integration with the Feeds module.

Code

function commerce_file_set_schema_target($source, $entity, $target, $value) {
  list($field_name, $sub_field) = explode(':', $target, 2);

  // Handle non-multiple value fields.
  if (!is_array($value)) {
    $value = array(
      $value,
    );
  }
  $field = isset($entity->{$field_name}) ? $entity->{$field_name} : array();
  $field_info = field_info_field($field_name);
  $singular = $field_info['cardinality'] == 1;
  $lang = LANGUAGE_NONE;
  foreach ($value as $i => $v) {
    $field[$lang][$i][$sub_field] = $v;
    if ($singular) {
      break;
    }
  }
  $entity->{$field_name} = $field;
}