function EntityRepository::getContentLanguageFromContexts

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::getContentLanguageFromContexts()
  2. 10 core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::getContentLanguageFromContexts()
  3. 9 core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::getContentLanguageFromContexts()
  4. 8.9.x core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::getContentLanguageFromContexts()

Retrieves the current content language from the specified contexts.

This is a BC layer to support plugin context system identifiers, the langcode key should be used instead and is preferred when given.

@internal

Parameters

string[] $contexts: An array of context items.

Return value

string|null A language code or NULL if no language context was provided.

2 calls to EntityRepository::getContentLanguageFromContexts()
EntityRepository::getActiveMultiple in core/lib/Drupal/Core/Entity/EntityRepository.php
Retrieves the active entity variants matching the specified context.
EntityRepository::getCanonicalMultiple in core/lib/Drupal/Core/Entity/EntityRepository.php
Retrieves the canonical entity variants matching the specified context.

File

core/lib/Drupal/Core/Entity/EntityRepository.php, line 215

Class

EntityRepository
Provides several mechanisms for retrieving entities.

Namespace

Drupal\Core\Entity

Code

protected function getContentLanguageFromContexts(array $contexts) {
  if (isset($contexts['langcode'])) {
    return $contexts['langcode'];
  }
  return $this->languageManager
    ->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
    ->getId();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.