Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-6589: Added optional parameter siteAccessList to SiteaccessResolver #910

Open
wants to merge 1 commit into
base: 4.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/lib/Siteaccess/NonAdminSiteaccessResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,33 @@ public function getSiteaccessesForLocation(
}

/**
* @param \Ibexa\Core\MVC\Symfony\SiteAccess[] $siteAccessList
*
* @return \Ibexa\Core\MVC\Symfony\SiteAccess[]
*/
public function getSiteAccessesListForLocation(
Location $location,
?int $versionNo = null,
?string $languageCode = null
?string $languageCode = null,
array $siteAccessList = []
): array {
return array_filter(
$this->siteaccessResolver->getSiteAccessesListForLocation($location, $versionNo, $languageCode),
$this->siteaccessResolver->getSiteAccessesListForLocation(
$location,
$versionNo,
$languageCode,
$siteAccessList
),
fn (SiteAccess $siteAccess): bool => !$this->isAdminSiteAccess($siteAccess)
);
}

public function getSiteAccessesListForContent(Content $content): array
{
public function getSiteAccessesListForContent(
Content $content,
array $siteAccessList = []
): array {
return array_filter(
$this->siteaccessResolver->getSiteAccessesListForContent($content),
$this->siteaccessResolver->getSiteAccessesListForContent($content, $siteAccessList),
fn (SiteAccess $siteAccess): bool => !$this->isAdminSiteAccess($siteAccess)
);
}
Expand Down
33 changes: 23 additions & 10 deletions src/lib/Siteaccess/SiteaccessResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,17 @@ public function getSiteaccessesForLocation(
return array_column($this->getSiteAccessesListForLocation($location, $versionNo, $languageCode), 'name');
}

/**
* @return \Ibexa\Core\MVC\Symfony\SiteAccess[]
*/
public function getSiteAccessesListForLocation(
Location $location,
?int $versionNo = null,
?string $languageCode = null
?string $languageCode = null,
array $siteAccessList = []
): array {
$contentInfo = $location->getContentInfo();
$versionInfo = $this->contentService->loadVersionInfo($contentInfo, $versionNo);
$languageCode = $languageCode ?? $contentInfo->mainLanguageCode;

$eligibleSiteAccesses = [];
/** @var \Ibexa\Core\MVC\Symfony\SiteAccess $siteAccess */
foreach ($this->siteAccessService->getAll() as $siteAccess) {
foreach ($this->getSiteAccessListToCheck($siteAccessList) as $siteAccess) {
$context = new SiteaccessPreviewVoterContext($location, $versionInfo, $siteAccess->name, $languageCode);
foreach ($this->siteAccessPreviewVoters as $siteAccessPreviewVoter) {
if ($siteAccessPreviewVoter->vote($context)) {
Expand All @@ -98,8 +94,10 @@ public function getSiteAccessesListForLocation(
return $eligibleSiteAccesses;
}

public function getSiteAccessesListForContent(Content $content): array
{
public function getSiteAccessesListForContent(
Content $content,
array $siteAccessList = []
): array {
$versionInfo = $content->getVersionInfo();
$contentInfo = $versionInfo->getContentInfo();

Expand All @@ -116,7 +114,12 @@ public function getSiteAccessesListForContent(Content $content): array
foreach ($eligibleLocations as $location) {
foreach ($eligibleLanguages as $language) {
$siteAccesses = array_merge(
$this->getSiteAccessesListForLocation($location, null, $language->languageCode),
$this->getSiteAccessesListForLocation(
$location,
null,
$language->languageCode,
$siteAccessList
),
$siteAccesses
);
}
Expand All @@ -137,6 +140,16 @@ public function getSiteAccessesList(): array
{
return iterator_to_array($this->siteAccessService->getAll());
}

/**
* @param array<\Ibexa\Core\MVC\Symfony\SiteAccess> $siteAccessList
*
* @return iterable<\Ibexa\Core\MVC\Symfony\SiteAccess>
*/
private function getSiteAccessListToCheck(array $siteAccessList = []): iterable
{
return !empty($siteAccessList) ? $siteAccessList : $this->siteAccessService->getAll();
}
}

class_alias(SiteaccessResolver::class, 'EzSystems\EzPlatformAdminUi\Siteaccess\SiteaccessResolver');
12 changes: 10 additions & 2 deletions src/lib/Siteaccess/SiteaccessResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,26 @@ public function getSiteaccessesForLocation(
): array;

/**
* @param \Ibexa\Core\MVC\Symfony\SiteAccess[] $siteAccessList
*
* @return \Ibexa\Core\MVC\Symfony\SiteAccess[]
*/
public function getSiteAccessesListForLocation(
Location $location,
?int $versionNo = null,
?string $languageCode = null
?string $languageCode = null,
array $siteAccessList = []
): array;

/**
* @param \Ibexa\Core\MVC\Symfony\SiteAccess[] $siteAccessList
*
* @return \Ibexa\Core\MVC\Symfony\SiteAccess[]
*/
public function getSiteAccessesListForContent(Content $content): array;
public function getSiteAccessesListForContent(
Content $content,
array $siteAccessList = []
): array;

/**
* @return \Ibexa\Core\MVC\Symfony\SiteAccess[]
Expand Down
Loading