You are here

function auto_entitylabel_entity_language in Automatic Entity Label 7

Returns the language code of the given entity.

Backward compatibility layer to ensure that installations running an older version of core where entity_language() is not available do not break.

Parameters

string $entity_type: An entity type.

object $entity: An entity object.

bool $check_language_property: A boolean if TRUE, will attempt to fetch the language code from $entity->language if the entity_language() function failed or does not exist. Default is TRUE.

1 call to auto_entitylabel_entity_language()
auto_entitylabel_set_title in ./auto_entitylabel.module
Sets the automatically generated entitylabel for the entity.

File

./auto_entitylabel.module, line 566
Allows hiding of entity label fields and automatic label creation.

Code

function auto_entitylabel_entity_language($entity_type, $entity, $check_language_property = TRUE) {
  $langcode = NULL;

  // When entity_translation is installed, if overrides the behavior of the
  // entity_language() function by returning the "active form language" instead
  // of the "original entity language". In this case we need to retrieve the
  // original language directly from the translation handler.
  if (module_exists('entity_translation')) {
    $handler = entity_translation_get_handler($entity_type, $entity);
    $langcode = $handler
      ->getLanguage();
  }
  elseif (function_exists('entity_language')) {
    $langcode = entity_language($entity_type, $entity);
  }
  elseif ($check_language_property && !empty($entity->language)) {
    $langcode = $entity->language;
  }
  return !empty($langcode) ? $langcode : LANGUAGE_NONE;
}