diff --git a/src/lib/Siteaccess/AbstractSiteaccessPreviewVoter.php b/src/lib/Siteaccess/AbstractSiteaccessPreviewVoter.php index f4629eee02..2666c62eff 100644 --- a/src/lib/Siteaccess/AbstractSiteaccessPreviewVoter.php +++ b/src/lib/Siteaccess/AbstractSiteaccessPreviewVoter.php @@ -34,7 +34,7 @@ public function vote(SiteaccessPreviewVoterContext $context): bool { $siteAccess = $context->getSiteaccess(); $location = $context->getLocation(); - $languageCode = $context->getLanguageCode(); + $languageCodes = $context->getLanguageCodes(); if (empty(array_intersect($this->getRootLocationIds($siteAccess), $location->getPath()))) { return false; @@ -50,7 +50,7 @@ public function vote(SiteaccessPreviewVoterContext $context): bool $siteAccess ); - return in_array($languageCode, $siteAccessLanguages, true); + return !empty(array_intersect($languageCodes, $siteAccessLanguages)); } protected function validateRepositoryMatch(string $siteaccess): bool diff --git a/src/lib/Siteaccess/SiteaccessPreviewVoterContext.php b/src/lib/Siteaccess/SiteaccessPreviewVoterContext.php index 7562651d2a..e16f87f05d 100644 --- a/src/lib/Siteaccess/SiteaccessPreviewVoterContext.php +++ b/src/lib/Siteaccess/SiteaccessPreviewVoterContext.php @@ -22,19 +22,22 @@ final class SiteaccessPreviewVoterContext /** @var string */ private $siteaccess; - /** @var string */ - private $languageCode; + /** @var array */ + private $languageCodes; + /** + * @param array $languageCodes + */ public function __construct( Location $location, VersionInfo $versionInfo, string $siteaccess, - string $languageCode + array $languageCodes ) { $this->location = $location; $this->versionInfo = $versionInfo; $this->siteaccess = $siteaccess; - $this->languageCode = $languageCode; + $this->languageCodes = $languageCodes; } /** @@ -54,11 +57,11 @@ public function getSiteaccess(): string } /** - * @return string + * @return array */ - public function getLanguageCode(): string + public function getLanguageCodes(): array { - return $this->languageCode; + return $this->languageCodes; } /** diff --git a/src/lib/Siteaccess/SiteaccessResolver.php b/src/lib/Siteaccess/SiteaccessResolver.php index 6df66b2bf5..02675bb426 100644 --- a/src/lib/Siteaccess/SiteaccessResolver.php +++ b/src/lib/Siteaccess/SiteaccessResolver.php @@ -81,12 +81,12 @@ public function getSiteAccessesListForLocation( ): array { $contentInfo = $location->getContentInfo(); $versionInfo = $this->contentService->loadVersionInfo($contentInfo, $versionNo); - $languageCode = $languageCode ?? $contentInfo->getMainLanguageCode(); + $languageCodes = $languageCode !== null ? [$languageCode] : $versionInfo->getLanguageCodes(); $eligibleSiteAccesses = []; /** @var \Ibexa\Core\MVC\Symfony\SiteAccess $siteAccess */ foreach ($this->siteAccessService->getAll() as $siteAccess) { - $context = new SiteaccessPreviewVoterContext($location, $versionInfo, $siteAccess->name, $languageCode); + $context = new SiteaccessPreviewVoterContext($location, $versionInfo, $siteAccess->name, $languageCodes); foreach ($this->siteAccessPreviewVoters as $siteAccessPreviewVoter) { if ($siteAccessPreviewVoter->vote($context)) { $eligibleSiteAccesses[] = $siteAccess; diff --git a/tests/lib/Siteaccess/AdminSiteaccessPreviewVoterTest.php b/tests/lib/Siteaccess/AdminSiteaccessPreviewVoterTest.php index bb13260321..131e6f1011 100644 --- a/tests/lib/Siteaccess/AdminSiteaccessPreviewVoterTest.php +++ b/tests/lib/Siteaccess/AdminSiteaccessPreviewVoterTest.php @@ -50,7 +50,7 @@ public function testVoteWithInvalidPath(): void ]); $siteaccess = 'site'; - $context = new SiteaccessPreviewVoterContext($location, $versionInfo, $siteaccess, $languageCode); + $context = new SiteaccessPreviewVoterContext($location, $versionInfo, $siteaccess, [$languageCode]); $this->mockConfigMethods($context); @@ -177,7 +177,7 @@ public function dataProviderForSiteaccessPreviewVoterContext(): array ]); $siteaccess = 'site'; - $context = new SiteaccessPreviewVoterContext($location, $versionInfo, $siteaccess, $languageCode); + $context = new SiteaccessPreviewVoterContext($location, $versionInfo, $siteaccess, [$languageCode]); return [ [