function location_feeds_set_country in Location Feeds 6
Same name and namespace in other branches
- 7 location_feeds.module \location_feeds_set_country()
Set the country and attempt to support non-iso country imports
Parameters
object $object: Either a user or node object dpending on where this is called
string $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_country'
- _location_feeds_fill_targets in ./
location_feeds.module - Helper function to add target fields
File
- ./
location_feeds.module, line 189 - This module provides location mappers to feed importers.
Code
function location_feeds_set_country($object, $target, $value) {
module_load_include('inc', 'location', 'location');
list($field_name, $sub_field) = explode(':', $target);
static $iso_list = array();
if (!is_array($value)) {
$value = array(
$value,
);
}
foreach ($value as $i => $val) {
$val = trim($val);
// if the country is in iso format or close to it, store
// it, else try to figure out the iso format
$isoval = $val;
if (location_standardize_country_code($isoval)) {
$object->{$field_name}[$i][$sub_field] = $isoval;
}
else {
// only load this once...
if (sizeof($iso_list) == 0) {
$iso_list = location_get_iso3166_list();
}
$keys = array_keys($iso_list, $val);
if (isset($keys[0])) {
$object->{$field_name}[$i][$sub_field] = $keys[0];
}
}
}
return $object;
}