From ece2fff97e4d72d50fcaa11b08dd3b6983d3443d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20D=C4=99bi=C5=84ski?= <58430570+mateuszdebinski@users.noreply.github.com> Date: Fri, 26 Nov 2021 12:59:36 +0100 Subject: [PATCH] IBX-1465: Prioritize current site access when choosing language (#2012) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IBX-1465: moved to the start of the siteAccess that is currently in use * corrected CS Co-authored-by: Mateusz Dębiński --- src/lib/UI/Config/Provider/Languages.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/UI/Config/Provider/Languages.php b/src/lib/UI/Config/Provider/Languages.php index f683ec295a..af77796c63 100644 --- a/src/lib/UI/Config/Provider/Languages.php +++ b/src/lib/UI/Config/Provider/Languages.php @@ -10,6 +10,7 @@ use eZ\Publish\API\Repository\LanguageService; use eZ\Publish\Core\MVC\ConfigResolverInterface; +use eZ\Publish\Core\MVC\Symfony\SiteAccess; use EzSystems\EzPlatformAdminUi\UI\Config\ProviderInterface; /** @@ -26,6 +27,9 @@ class Languages implements ProviderInterface /** @var string[] */ private $siteAccesses; + /** @var \eZ\Publish\Core\MVC\Symfony\SiteAccess */ + private $siteAccess; + /** * @param \eZ\Publish\API\Repository\LanguageService $languageService * @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver @@ -34,10 +38,12 @@ class Languages implements ProviderInterface public function __construct( LanguageService $languageService, ConfigResolverInterface $configResolver, + SiteAccess $siteAccess, array $siteAccesses ) { $this->languageService = $languageService; $this->configResolver = $configResolver; + $this->siteAccess = $siteAccess; $this->siteAccesses = $siteAccesses; } @@ -86,8 +92,9 @@ protected function getLanguagesPriority(array $languagesMap): array { $priority = []; $fallback = []; + $siteAccesses = array_unique(array_merge([$this->siteAccess->name], $this->siteAccesses)); - foreach ($this->siteAccesses as $siteAccess) { + foreach ($siteAccesses as $siteAccess) { $siteAccessLanguages = $this->configResolver->getParameter('languages', null, $siteAccess); $priority[] = array_shift($siteAccessLanguages); $fallback = array_merge($fallback, $siteAccessLanguages);