7 common.inc entity_language($entity_type, $entity)

Returns the language of an entity.


$entity_type: The entity type; e.g., 'node' or 'user'.

$entity: The entity for which to get the language.

Return value

A valid language code or NULL if the entity has no language support.

25 calls to entity_language()
comment_form in modules/comment/comment.module
Generate the basic commenting form, for appending to a node or display on a separate page.
comment_submit in modules/comment/comment.module
Prepare a comment for submission.
LocaleCommentLanguageFunctionalTest::testCommentLanguage in modules/locale/locale.test
Test that comment language is properly set.
locale_field_entity_form_submit in modules/locale/locale.module
Handles field language on submit for the given entity type.
NodeTokenReplaceTestCase::testNodeTokenReplacement in modules/node/node.test
Creates a node, then tests the tokens generated from it.

... See full list


includes/common.inc, line 8178
Common functions that many Drupal modules will need to reference.


function entity_language($entity_type, $entity) {
  $info = entity_get_info($entity_type);

  // Invoke the callback to get the language. If there is no callback, try to
  // get it from a property of the entity, otherwise NULL.
  if (isset($info['language callback']) && function_exists($info['language callback'])) {
    $langcode = $info['language callback']($entity_type, $entity);
  elseif (!empty($info['entity keys']['language']) && isset($entity->{$info['entity keys']['language']})) {
    $langcode = $entity->{$info['entity keys']['language']};
  else {
    // The value returned in D8 would be LANGUAGE_NONE, we cannot use it here to
    // preserve backward compatibility. In fact this function has been
    // introduced very late in the D7 life cycle, mainly as the proper default
    // for field_attach_form(). By returning LANGUAGE_NONE when no language
    // information is available, we would introduce a potentially BC-breaking
    // API change, since field_attach_form() defaults to the default language
    // instead of LANGUAGE_NONE. Moreover this allows us to distinguish between
    // entities that have no language specified from ones that do not have
    // language support at all.
    $langcode = NULL;

  return $langcode;


Note that this method was apparently added in D7.15 and is not available in earlier releases of D7. Use with caution in contrib code!

It wasn't pretty clear to me, but I was passing as second parameter a Entity Wrapper and it seems to be wrong:

 *  Implements hook_node_update().
function my_module_node_update($node) {
$node_wrapper = entity_metadata_wrapper('node', $node);


// Using the wrapper is WRONG in some situations leading to an EntityMetadataWrapperException: Unknown data property translations...
$langcode = entity_language('node', $node_wrapper);


// This seems to work OK in all situations (Since D7.15)
$langcode = entity_language('node', $node);

I didn't debug the error but maybe it is useful for someone.