W3cubDocs

/Drupal 8

public function Entity::language

public Entity::language()

Gets the language of the entity.

Return value

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

Overrides EntityInterface::language

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

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Entity.php/function/Entity::language/8.1.x