Skip to content

Commit

Permalink
IBX-9293: List site accesses for location based on version info's lan…
Browse files Browse the repository at this point in the history
…guages
  • Loading branch information
barw4 committed Jan 14, 2025
1 parent 9c88bf4 commit 07315e9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/lib/Siteaccess/AbstractSiteaccessPreviewVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
17 changes: 10 additions & 7 deletions src/lib/Siteaccess/SiteaccessPreviewVoterContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,22 @@ final class SiteaccessPreviewVoterContext
/** @var string */
private $siteaccess;

/** @var string */
private $languageCode;
/** @var array<string> */
private $languageCodes;

/**
* @param array<int, string> $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;
}

/**
Expand All @@ -54,11 +57,11 @@ public function getSiteaccess(): string
}

/**
* @return string
* @return array<int, string>
*/
public function getLanguageCode(): string
public function getLanguageCodes(): array
{
return $this->languageCode;
return $this->languageCodes;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Siteaccess/SiteaccessResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Siteaccess/AdminSiteaccessPreviewVoterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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

0 comments on commit 07315e9

Please sign in to comment.