You are here

function entity_translation_language in Entity Translation 7

Entity language callback.

This callback changes the entity language from the actual one to the active language. This overriding allows to obtain language dependent form widgets where multilingual values are supported (e.g. field or path alias widgets) even if the code was not originally written with supporting multiple values per language in mind.

The main drawback of this approach is that code needing to access the actual language in the entity form build/validation/submit workflow cannot rely on the entity_language() function. On the other hand in these scenarios assuming the presence of Entity translation should be safe, thus developers can rely on the EntityTranslationHandlerInterface::getLanguage() method.

Parameters

string $entity_type: The the type of the entity.

object $entity: The entity whose language has to be returned.

Return value

string A valid language code.

1 string reference to 'entity_translation_language'
entity_translation_entity_info_alter in ./entity_translation.module
Implements hook_entity_info_alter().

File

./entity_translation.module, line 1869

Code

function entity_translation_language($entity_type, $entity) {
  $handler = entity_translation_get_handler($entity_type, $entity);
  if (!$handler) {
    return LANGUAGE_NONE;
  }
  if (entity_translation_enabled($entity_type, $entity)) {
    $langcode = $handler
      ->getActiveLanguage();
    return $langcode ? $langcode : $handler
      ->getLanguage();
  }
  else {
    return $handler
      ->getLanguage();
  }
}