diff --git a/src/bundle/Resources/config/services/siteaccess.yml b/src/bundle/Resources/config/services/siteaccess.yml index 43aa47b6fa..286d6a0b66 100644 --- a/src/bundle/Resources/config/services/siteaccess.yml +++ b/src/bundle/Resources/config/services/siteaccess.yml @@ -7,3 +7,4 @@ services: EzSystems\EzPlatformAdminUi\Siteaccess\SiteaccessResolverInterface: '@EzSystems\EzPlatformAdminUi\Siteaccess\SiteaccessResolver' EzSystems\EzPlatformAdminUi\Siteaccess\SiteaccessResolver: ~ EzSystems\EzPlatformAdminUi\Siteaccess\NonAdminSiteaccessResolver: ~ + EzSystems\EzPlatformAdminUi\Siteaccess\RootLocationsProvider: ~ diff --git a/src/lib/Siteaccess/RootLocationsProvider.php b/src/lib/Siteaccess/RootLocationsProvider.php new file mode 100644 index 0000000000..33ee2a3221 --- /dev/null +++ b/src/lib/Siteaccess/RootLocationsProvider.php @@ -0,0 +1,59 @@ +configResolver = $configResolver; + } + + /** + * Gets all root locations (e.g. root location for Forms and Media) available in given siteaccess. + * + * @param string $siteaccess + * + * @return array + */ + public function getRootLocations(string $siteaccess): array + { + $rootLocations = []; + + foreach (self::ROOT_LOCATIONS_PARAMETER_NAMES as $rootLocationParameterName) { + if ($this->configResolver->hasParameter( + $rootLocationParameterName, + null, + $siteaccess + )) { + $rootLocations[] = $this->configResolver->getParameter( + $rootLocationParameterName, + null, + $siteaccess + ); + } + } + + return $rootLocations; + } +} diff --git a/src/lib/Siteaccess/SiteaccessResolver.php b/src/lib/Siteaccess/SiteaccessResolver.php index 966416649b..097b693ef4 100644 --- a/src/lib/Siteaccess/SiteaccessResolver.php +++ b/src/lib/Siteaccess/SiteaccessResolver.php @@ -14,22 +14,40 @@ class SiteaccessResolver implements SiteaccessResolverInterface { - /** @var ConfigResolverInterface */ + /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */ private $configResolver; - /** @var ContentService */ + /** @var \eZ\Publish\API\Repository\ContentService */ private $contentService; + /** @var \EzSystems\EzPlatformAdminUi\Siteaccess\RootLocationsProvider */ + private $rootLocationsProvider; + /** - * @param ConfigResolverInterface $configResolver - * @param ContentService $contentService + * @param \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver + * @param \eZ\Publish\API\Repository\ContentService $contentService + * @param \EzSystems\EzPlatformAdminUi\Siteaccess\RootLocationsProvider $rootLocationsProvider */ - public function __construct(ConfigResolverInterface $configResolver, ContentService $contentService) - { + public function __construct( + ConfigResolverInterface $configResolver, + ContentService $contentService, + RootLocationsProvider $rootLocationsProvider + ) { $this->configResolver = $configResolver; $this->contentService = $contentService; + $this->rootLocationsProvider = $rootLocationsProvider; } + /** + * @param \eZ\Publish\API\Repository\Values\Content\Location $location + * @param int|null $versionNo + * @param string|null $languageCode + * + * @return array + * + * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException + * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException + */ public function getSiteaccessesForLocation( Location $location, int $versionNo = null, @@ -42,12 +60,9 @@ public function getSiteaccessesForLocation( $eligibleSiteaccesses = []; foreach ($this->getSiteaccesses() as $siteaccess) { - $rootLocationId = $this->configResolver->getParameter( - 'content.tree_root.location_id', - null, - $siteaccess - ); - if (!in_array($rootLocationId, $location->path)) { + $rootLocations = $this->rootLocationsProvider->getRootLocations($siteaccess); + + if (empty(array_intersect($rootLocations, $location->path))) { continue; }