public function EntityNG::getTranslationLanguages

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

Overrides Entity::getTranslationLanguages

1 call to EntityNG::getTranslationLanguages()
EntityNG::translations in drupal/core/lib/Drupal/Core/Entity/EntityNG.php
Overrides Entity::translations().

File

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

Class

EntityNG
Implements Entity Field API specific enhancements to the Entity class.

Namespace

Drupal\Core\Entity

Code

public function getTranslationLanguages($include_default = TRUE) {
  $translations = array();
  $definitions = $this
    ->getPropertyDefinitions();

  // Build an array with the translation langcodes set as keys. Empty
  // translations should not be included and must be skipped.
  foreach ($this
    ->getProperties() as $name => $property) {
    foreach ($this->fields[$name] as $langcode => $field) {
      if (!$field
        ->isEmpty()) {
        $translations[$langcode] = TRUE;
      }
      if (isset($this->values[$name])) {
        foreach ($this->values[$name] as $langcode => $values) {

          // If a value is there but the field object is empty, it has been
          // unset, so we need to skip the field also.
          if ($values && !empty($definitions[$name]['translatable']) && !(isset($this->fields[$name][$langcode]) && $this->fields[$name][$langcode]
            ->isEmpty())) {
            $translations[$langcode] = TRUE;
          }
        }
      }
    }
  }

  // We include the default language code instead of the
  // Language::LANGCODE_DEFAULT constant.
  unset($translations[Language::LANGCODE_DEFAULT]);
  if ($include_default) {
    $translations[$this
      ->language()->langcode] = TRUE;
  }

  // Now load language objects based upon translation langcodes.
  return array_intersect_key(language_list(Language::STATE_ALL), $translations);
}