You are here

protected function ContentEntityBase::getLanguages in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::getLanguages()
  2. 9 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::getLanguages()
3 calls to ContentEntityBase::getLanguages()
ContentEntityBase::addTranslation in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Adds a new translation to the translatable object.
ContentEntityBase::getTranslationLanguages in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Returns the languages the data is translated to.
ContentEntityBase::language in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Gets the language of the entity.

File

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

Class

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

Namespace

Drupal\Core\Entity

Code

protected function getLanguages() {
  if (empty($this->languages)) {
    $this->languages = $this
      ->languageManager()
      ->getLanguages(LanguageInterface::STATE_ALL);

    // If the entity references a language that is not or no longer available,
    // we return a mock language object to avoid disrupting the consuming
    // code.
    if (!isset($this->languages[$this->defaultLangcode])) {
      $this->languages[$this->defaultLangcode] = new Language([
        'id' => $this->defaultLangcode,
      ]);
    }
  }
  return $this->languages;
}