8.2.x Entity.php public Entity::language()
8.0.x Entity.php public Entity::language()
8.1.x Entity.php public Entity::language()
8.3.x Entity.php public Entity::language()

Gets the language of the entity.

Return value

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

Overrides EntityInterface::language

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

File

core/lib/Drupal/Core/Entity/Entity.php, line 346

Class

Entity
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(array('id' => $langcode));
  return $language;
}