public function Entity::getTranslationLanguages

Implements \Drupal\Core\TypedData\TranslatableInterface::getTranslationLanguages().

Overrides TranslatableInterface::getTranslationLanguages

1 call to Entity::getTranslationLanguages()
Entity::translations in drupal/core/lib/Drupal/Core/Entity/Entity.php
Returns the languages the entity is translated to.
1 method overrides Entity::getTranslationLanguages()

File

drupal/core/lib/Drupal/Core/Entity/Entity.php, line 317
Contains \Drupal\Core\Entity\Entity.

Class

Entity
Defines a base entity class.

Namespace

Drupal\Core\Entity

Code

public function getTranslationLanguages($include_default = TRUE) {

  // @todo: Replace by EntityNG implementation once all entity types have been
  // converted to use the entity field API.
  $default_language = $this
    ->language();
  $languages = array(
    $default_language->langcode => $default_language,
  );
  $entity_info = $this
    ->entityInfo();
  if ($entity_info['fieldable']) {

    // Go through translatable properties and determine all languages for
    // which translated values are available.
    foreach (field_info_instances($this->entityType, $this
      ->bundle()) as $field_name => $instance) {
      $field = field_info_field($field_name);
      if (field_is_translatable($this->entityType, $field) && isset($this->{$field_name})) {
        foreach (array_filter($this->{$field_name}) as $langcode => $value) {
          $languages[$langcode] = TRUE;
        }
      }
    }
    $languages = array_intersect_key(language_list(Language::STATE_ALL), $languages);
  }
  if (empty($include_default)) {
    unset($languages[$default_language->langcode]);
  }
  return $languages;
}