You are here

public function EntityBase::language in Drupal 8

Same name and namespace 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()

Gets the language of the entity.

Return value

\Drupal\Core\Language\LanguageInterface The language object.

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;
}