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;
}
doc_Drupal
2016-10-29 09:04:21
Comments
Leave a Comment

Please login to continue.