function lingotek_field_language_alter in Lingotek Translation 7.6
Same name and namespace in other branches
- 7.7 lingotek.module \lingotek_field_language_alter()
- 7.2 lingotek.module \lingotek_field_language_alter()
- 7.3 lingotek.module \lingotek_field_language_alter()
- 7.4 lingotek.module \lingotek_field_language_alter()
- 7.5 lingotek.module \lingotek_field_language_alter()
Implements hook_field_language_alter().
File
- ./
lingotek.module, line 2158
Code
function lingotek_field_language_alter(&$display_language, $context) {
$entity = $context['entity'];
$entity_type = $context['entity_type'];
// If no language is set on the entity itself, do nothing.
if (!isset($entity->language) || empty($entity->language)) {
return;
}
// If site admins have specifically excluded fallback behavior, or if the entity
// type is not handled by the Lingotek Translation module, then do nothing.
if (!variable_get('locale_field_language_fallback', TRUE) || !lingotek_managed_entity($entity_type, $entity)) {
return;
}
// Comments may be in a state where content only exists in the source language
// because Lingotek translation hasn't finished yet, or synchonization with
// Lingotek hasn't yet occurred. In this case, fall back to displaying
// the default language for each field.
$field_collection_field_types = field_read_fields(array(
'type' => 'field_collection',
));
foreach ($display_language as $field => $display_language_code) {
$is_field_collection = isset($field_collection_field_types[$field]);
if ($is_field_collection) {
continue;
}
// Use the entity language if the field does not have an entry in the display
// language and if it is not a node-based source or translation.
if (!isset($entity->{$field}[$display_language_code]) && (empty($entity->tnid) || $entity->tnid === 0)) {
$display_language[$field] = $entity->language;
}
}
}