function hms_field_feeds_set_target in HMS Field 7
HMS field callback for mapping.
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.
Parameters
$source: A FeedsSource object.
$entity: The entity to map to.
$target: The target key on $entity to map to.
$value: The value to map. MUST be an array.
$mapping: Array of mapping settings for current value.
$input_format: TRUE if an input format should be applied.
1 string reference to 'hms_field_feeds_set_target'
File
- ./
hms_field.feeds.inc, line 50 - Feeds mapping implementation for the hms_feeds module.
Code
function hms_field_feeds_set_target($source, $entity, $target, $value, $mapping, $input_format = FALSE) {
// Don't do anything if we weren't given any data.
if (empty($value)) {
return;
}
// Assume that the passed in value could really be any number of values.
if (is_array($value)) {
$values = $value;
}
else {
$values = array(
$value,
);
}
// Get some useful field information.
$info = field_info_field($target);
// Set the language of the field depending on the mapping.
$language = isset($mapping['language']) ? $mapping['language'] : LANGUAGE_NONE;
// Iterate over all values.
$iterator = 0;
$field = isset($entity->{$target}) ? $entity->{$target} : array();
foreach ($values as $value) {
// Only process if this value was set for this instance.
if ($value) {
$field[$language][$iterator]['value'] = $value;
}
// Break out of the loop if this field is single-valued.
if ($info['cardinality'] == 1) {
break;
}
$iterator++;
}
// Add the field to the entity definition.
$entity->{$target} = $field;
}