function getlocations_feeds_set_country in Get Locations 7
Same name and namespace in other branches
- 7.2 modules/getlocations_feeds/getlocations_feeds.module \getlocations_feeds_set_country()
Set the country and attempt to support non-iso country imports
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 'getlocations_feeds_set_country'
- _getlocations_feeds_fill_targets in modules/
getlocations_feeds/ getlocations_feeds.module - Helper function to add target fields
File
- modules/
getlocations_feeds/ getlocations_feeds.module, line 153 - getlocations_feeds.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function getlocations_feeds_set_country($source, $entity, $target, $value) {
if (empty($value)) {
$getlocations_fields_defaults = getlocations_fields_defaults();
$value = $getlocations_fields_defaults['country'];
}
if (!is_array($value)) {
$value = array(
$value,
);
}
list($field_name, $sub_field) = explode(':', $target);
foreach ($value as $i => $val) {
if (!isset($entity->{$field_name}['und'][$i]['settings'])) {
$entity->{$field_name}['und'][$i]['settings'] = getlocations_feeds_get_field_info($field_name);
}
// set default
$entity->{$field_name}['und'][$i][$sub_field] = $entity->{$field_name}['und'][$i]['settings']['country'];
$val = trim($val);
if (drupal_strlen($val) == 2) {
// we have a code
if (getlocations_get_country_name($val)) {
$entity->{$field_name}['und'][$i][$sub_field] = drupal_strtoupper($val);
}
}
else {
// full country name
if ($id = getlocations_get_country_id($val)) {
$entity->{$field_name}['und'][$i][$sub_field] = $id;
}
}
}
return $entity;
}