function getlocations_fields_load_locations in Get Locations 7.2
Same name and namespace in other branches
- 7 modules/getlocations_fields/getlocations_fields.module \getlocations_fields_load_locations()
2 calls to getlocations_fields_load_locations()
- getlocations_fields_save_locations in modules/
getlocations_fields/ getlocations_fields.module - getlocations_load_locations in ./
getlocations.module - Function to fetch locations
File
- modules/
getlocations_fields/ getlocations_fields.module, line 2255 - getlocations_fields.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL
Code
function getlocations_fields_load_locations($entity_id, $entity_type, $field_name = '') {
module_load_include('inc', 'getlocations_fields', 'getlocations_fields.functions');
$getlocations_fields_defaults = getlocations_fields_defaults();
$getlocations_defaults = getlocations_defaults();
// backward compat
$translate_keys = array(
'nid' => 'node',
'vid' => 'node',
'uid' => 'user',
'cid' => 'comment',
'tid' => 'taxonomy_term',
);
if (isset($translate_keys[$entity_type])) {
$entity_type = $translate_keys[$entity_type];
}
$locations = array();
$entity_get_info = entity_get_info($entity_type);
$entity_key = $entity_get_info['entity keys']['id'];
$load_hook = $entity_get_info['load hook'];
$fieldable = $entity_get_info['fieldable'];
if ($fieldable) {
$entity = $load_hook($entity_id);
if ($field_name) {
$field_names = array(
$field_name,
);
}
else {
$field_names = getlocations_get_fieldnames();
}
$ct = 0;
foreach ($field_names as $fn) {
if (isset($entity->{$fn})) {
$lang = $entity->language;
if ($field_lang = getlocations_get_field_lang($entity_id, $entity_type, $fn)) {
$lang = $field_lang;
}
if (isset($entity->{$fn}[$lang])) {
foreach ($entity->{$fn}[$lang] as $location) {
$locations[$ct] = $location;
$locations[$ct]['language'] = $lang;
$ct++;
}
}
}
}
}
return $locations;
}