You are here

public function Entity::language in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/Entity.php \Drupal\Core\Entity\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 350
Contains \Drupal\Core\Entity\Entity.

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