Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

AbstractLanguageResolver.php
Go to the documentation of this file.
1 <?php
2
7 declare(strict_types=1);
8
9 namespace eZ\Publish\Core\Repository\SiteAccessAware\Language;
10
11 use eZ\Publish\API\Repository\LanguageResolver as APILanguageResolver;
12 use eZ\Publish\API\Repository\Values\Content\Language;
13
19 abstract class AbstractLanguageResolver implements APILanguageResolver
20 {
22 private $defaultUseAlwaysAvailable;
23
25 private $defaultShowAllTranslations;
26
37 private $contextLanguage;
38
43 public function __construct(
44 bool $defaultUseAlwaysAvailable = true,
45 bool $defaultShowAllTranslations = false
46 ) {
47 $this->defaultUseAlwaysAvailable = $defaultUseAlwaysAvailable;
48 $this->defaultShowAllTranslations = $defaultShowAllTranslations;
49 }
50
56 abstract protected function getConfiguredLanguages(): array;
57
68 final public function setContextLanguage(?string $contextLanguage): void
69 {
70 $this->contextLanguage = $contextLanguage;
71 }
72
78 final public function getContextLanguage(): ?string
79 {
80 return $this->contextLanguage;
81 }
82
90 final public function getPrioritizedLanguages(?array $forcedLanguages = null): array
91 {
92 // Skip if languages param has been set by API user
93 if ($forcedLanguages !== null) {
94 return $forcedLanguages;
95 }
96
97 // Detect if we should load all languages by default
98 if ($this->defaultShowAllTranslations) {
99 return Language::ALL;
100 }
101
102 // create language based on context and configuration, where context language is made most important one
103 $languages = [];
104 if ($this->contextLanguage !== null) {
105 $languages[] = $this->contextLanguage;
106 }
107
108 return array_values(array_unique(array_merge($languages, $this->getConfiguredLanguages())));
109 }
110
116 final public function setDefaultUseAlwaysAvailable(bool $defaultUseAlwaysAvailable): void
117 {
118 $this->defaultUseAlwaysAvailable = $defaultUseAlwaysAvailable;
119 }
120
129 final public function getUseAlwaysAvailable(?bool $forcedUseAlwaysAvailable = null): bool
130 {
131 if ($forcedUseAlwaysAvailable !== null) {
132 return $forcedUseAlwaysAvailable;
133 }
134
135 return $this->defaultUseAlwaysAvailable;
136 }
137
143 final public function setShowAllTranslations(bool $defaultShowAllTranslations): void
144 {
145 $this->defaultShowAllTranslations = $defaultShowAllTranslations;
146 }
147
156 final public function getShowAllTranslations(?bool $forcedShowAllTranslations = null): bool
157 {
158 if ($forcedShowAllTranslations !== null) {
159 return $forcedShowAllTranslations;
160 }
161
162 return $this->defaultShowAllTranslations;
163 }
164 }
eZ\Publish\API\Repository\Values\Content\Language
Definition: API/Repository/Values/Content/Language.php:20
eZ\Publish\API\Repository\Values\Content\Language\ALL
const ALL
Constant for use in API's to specify that you want to load all languages.
Definition: API/Repository/Values/Content/Language.php:24
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver
Common abstract implementation of Language resolver.
Definition: AbstractLanguageResolver.php:20
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\$contextLanguage
$contextLanguage
Definition: AbstractLanguageResolver.php:37
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\getUseAlwaysAvailable
getUseAlwaysAvailable(?bool $forcedUseAlwaysAvailable=null)
Get currently set UseAlwaysAvailable.
Definition: AbstractLanguageResolver.php:129
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\getContextLanguage
getContextLanguage()
Get context language currently set by custom logic.
Definition: AbstractLanguageResolver.php:78
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\getConfiguredLanguages
getConfiguredLanguages()
Get list of languages configured via dedicated layer.
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\$defaultShowAllTranslations
$defaultShowAllTranslations
Definition: AbstractLanguageResolver.php:25
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\__construct
__construct(bool $defaultUseAlwaysAvailable=true, bool $defaultShowAllTranslations=false)
Definition: AbstractLanguageResolver.php:43
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\setShowAllTranslations
setShowAllTranslations(bool $defaultShowAllTranslations)
For use by event listening to config resolver scope changes (or other event changing configured langu...
Definition: AbstractLanguageResolver.php:143
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\setContextLanguage
setContextLanguage(?string $contextLanguage)
For use by custom events / logic setting language for all retrieved objects from repository.
Definition: AbstractLanguageResolver.php:68
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\getShowAllTranslations
getShowAllTranslations(?bool $forcedShowAllTranslations=null)
Get currently set showAllTranslations.
Definition: AbstractLanguageResolver.php:156
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\getPrioritizedLanguages
getPrioritizedLanguages(?array $forcedLanguages=null)
Get prioritized languages taking into account forced and context languages.
Definition: AbstractLanguageResolver.php:90
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\$defaultUseAlwaysAvailable
$defaultUseAlwaysAvailable
Definition: AbstractLanguageResolver.php:22
eZ\Publish\Core\Repository\SiteAccessAware\Language\AbstractLanguageResolver\setDefaultUseAlwaysAvailable
setDefaultUseAlwaysAvailable(bool $defaultUseAlwaysAvailable)
For use by event listening to config resolver scope changes (or other event changing configured langu...
Definition: AbstractLanguageResolver.php:116
eZ\Publish\API\Repository\LanguageResolver
Resolve language settings for Repository layer.
Definition: Publish/API/Repository/LanguageResolver.php:15
eZ\Publish\Core\Repository\SiteAccessAware\Language
Definition: AbstractLanguageResolver.php:9
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.