Returns the language of an entity.

Parameters

$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.

23 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

File

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

Code

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;
}