ContentEntityBase::getTranslationLanguages

public ContentEntityBase::getTranslationLanguages($include_default = TRUE)

Returns the languages the data is translated to.

Parameters

bool $include_default: (optional) Whether the default language should be included. Defaults to TRUE.

Return value

\Drupal\Core\Language\LanguageInterface[] An associative array of language objects, keyed by language codes.

Overrides TranslatableInterface::getTranslationLanguages

File

core/lib/Drupal/Core/Entity/ContentEntityBase.php, line 857

Class

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

Namespace

Drupal\Core\Entity

Code

public function getTranslationLanguages($include_default = TRUE) {
  $translations = array_filter($this->translations, function($translation) {
    return $translation['status'];
  });
  unset($translations[LanguageInterface::LANGCODE_DEFAULT]);

  if ($include_default) {
    $translations[$this->defaultLangcode] = TRUE;
  }

  // Now load language objects based upon translation langcodes.
  return array_intersect_key($this->getLanguages(), $translations);
}
doc_Drupal
2016-10-29 08:56:56
Comments
Leave a Comment

Please login to continue.