function EntityRepository::getContentLanguageFromContexts

Same name in other branches
  1. 9 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. 11.x 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 224

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

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