You are here

protected function EntityRepository::getContentLanguageFromContexts in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/EntityRepository.php \Drupal\Core\Entity\EntityRepository::getContentLanguageFromContexts()

Retrieves the current content language from the specified contexts.

Parameters

\Drupal\Core\Plugin\Context\ContextInterface[] $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 218

Class

EntityRepository
Provides several mechanisms for retrieving entities.

Namespace

Drupal\Core\Entity

Code

protected function getContentLanguageFromContexts(array $contexts) {

  // Content language might not be configurable, in which case we need to fall
  // back to a configurable language type.
  foreach ([
    LanguageInterface::TYPE_CONTENT,
    LanguageInterface::TYPE_INTERFACE,
  ] as $language_type) {
    $context_id = '@language.current_language_context:' . $language_type;
    if (isset($contexts[$context_id])) {
      return $contexts[$context_id]
        ->getContextValue()
        ->getId();
    }
  }
  return $this->languageManager
    ->getDefaultLanguage()
    ->getId();
}