function ContentEntityBase::getLanguages

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::getLanguages()
  2. 10 core/lib/Drupal/Core/Entity/ContentEntityBase.php \Drupal\Core\Entity\ContentEntityBase::getLanguages()
  3. 11.x 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
ContentEntityBase::getTranslationLanguages in core/lib/Drupal/Core/Entity/ContentEntityBase.php
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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.