function lingotek_get_host_language in Lingotek Translation 7.5
Same name and namespace in other branches
- 7.7 lingotek.module \lingotek_get_host_language()
- 7.6 lingotek.module \lingotek_get_host_language()
1 call to lingotek_get_host_language()
File
- ./
lingotek.module, line 1838
Code
function lingotek_get_host_language($entity_type, $entity, $read_only = TRUE) {
// The language attribute for field collections will be empty.
if (!empty($entity->language)) {
return $entity->language;
}
$site_default_lang = language_default();
$site_default_langcode = $site_default_lang->language;
if (!$read_only && isset($_POST['language'])) {
return $_POST['language'];
}
$host = module_exists('field_collection') && $entity_type == 'field_collection_item' ? lingotek_get_fc_parent($entity) : NULL;
if (!$host) {
// unable to locate parent. Abort.
return $site_default_langcode;
}
$max_field_collection_depth = 10;
// bubble up to the true parent to get its language,
// which adds support for deeply nested entity collections
for ($i = 0; $i < $max_field_collection_depth; $i++) {
if ($host instanceof FieldCollectionItemEntity) {
$host = lingotek_get_fc_parent($host);
continue;
}
break;
}
if (!$host) {
return $site_default_langcode;
}
if ($host instanceof FieldCollectionItemEntity) {
LingotekLog::error('Field collections nested too deeply, possibly a loop?: @entity', array(
'@entity' => print_r($entity, TRUE),
));
}
if (isset($host->language)) {
return $host->language;
}
return $site_default_langcode;
}