Skip to content

Commit

Permalink
IBX-1465: Prioritize current site access when choosing language (#2012)
Browse files Browse the repository at this point in the history
* IBX-1465: moved to the start of the siteAccess that is currently in use

* corrected CS

Co-authored-by: Mateusz Dębiński <mateusz.debinski@ibexa.co>
  • Loading branch information
mateuszdebinski and Mateusz Dębiński authored Nov 26, 2021
1 parent 393bd0a commit ece2fff
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/UI/Config/Provider/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ece2fff

Please # to comment.