function EntityBase::language

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityBase.php \Drupal\Core\Entity\EntityBase::language()
  2. 10 core/lib/Drupal/Core/Entity/EntityBase.php \Drupal\Core\Entity\EntityBase::language()
  3. 11.x core/lib/Drupal/Core/Entity/EntityBase.php \Drupal\Core\Entity\EntityBase::language()

Overrides EntityInterface::language

1 call to EntityBase::language()
EntityBase::toUrl in core/lib/Drupal/Core/Entity/EntityBase.php
Gets the URL object for the entity.
1 method overrides EntityBase::language()
ContentEntityBase::language in core/lib/Drupal/Core/Entity/ContentEntityBase.php
Gets the language of the entity.

File

core/lib/Drupal/Core/Entity/EntityBase.php, line 376

Class

EntityBase
Defines a base entity class.

Namespace

Drupal\Core\Entity

Code

public function language() {
    if ($key = $this->getEntityType()
        ->getKey('langcode')) {
        $langcode = $this->{$key};
        $language = $this->languageManager()
            ->getLanguage($langcode);
        if ($language) {
            return $language;
        }
    }
    // Make sure we return a proper language object.
    $langcode = !empty($this->langcode) ? $this->langcode : LanguageInterface::LANGCODE_NOT_SPECIFIED;
    $language = new Language([
        'id' => $langcode,
    ]);
    return $language;
}

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