function location_feeds_set_target in Location Feeds 7
Same name and namespace in other branches
- 6 location_feeds.module \location_feeds_set_target()
Implements feed_set_target().
Parameters
$source: Field mapper source settings.
$entity: Either a user or node object dpending on where this is called
$target: When targeting sub arrays the '][' is used to drill down. Note that this implementation is lazy ... we assume just depth=2
$value:
Return value
object
1 string reference to 'location_feeds_set_target'
- _location_feeds_fill_targets in ./
location_feeds.module - Helper function to add target fields
File
- ./
location_feeds.module, line 153 - This module provides location mappers to feed importers.
Code
function location_feeds_set_target($source, $entity, $target, $value) {
list($field_name, $sub_field) = explode(':', $target);
if (strpos($sub_field, '][') !== FALSE) {
list($sub_field, $last_field) = explode('][', $sub_field, 2);
}
if (!is_array($value)) {
$value = array(
$value,
);
}
// Check if this is a cck field since they're added to the node
// differently.
$cck = preg_match('/^field_.+/', $target);
foreach ($value as $i => $val) {
$val = trim($val);
// location_cck has issues with empty fields, so bail if we find one.
if ($val !== FALSE && $val !== 0 && empty($val)) {
continue;
}
if (isset($last_field)) {
if ($cck) {
if (!isset($entity->{$field_name}['und'][$i]['location_settings'])) {
$entity->{$field_name}['und'][$i]['location_settings'] = location_feeds_get_field_info($field_name);
}
$entity->{$field_name}['und'][$i][$sub_field][$last_field] = $val;
}
else {
$entity->{$field_name}[$i][$sub_field][$last_field] = $val;
}
}
else {
if ($cck) {
if (!isset($entity->{$field_name}['und'][$i]['location_settings'])) {
$entity->{$field_name}['und'][$i]['location_settings'] = location_feeds_get_field_info($field_name);
}
$entity->{$field_name}['und'][$i][$sub_field] = $val;
}
else {
$entity->{$field_name}[$i][$sub_field] = $val;
}
}
}
return $entity;
}