Skip to content

Commit

Permalink
EZEE-2533: Error HTTP 400 trying to preview Form during creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mikadamczyk committed Mar 11, 2019
1 parent b0f9146 commit 039b3db
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/bundle/Resources/config/services/siteaccess.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ~
59 changes: 59 additions & 0 deletions src/lib/Siteaccess/RootLocationsProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace EzSystems\EzPlatformAdminUi\Siteaccess;

use eZ\Publish\Core\MVC\ConfigResolverInterface;

class RootLocationsProvider
{
private const ROOT_LOCATIONS_PARAMETER_NAMES = [
'content.tree_root.location_id',
'location_ids.media',
'form_builder.forms_location_id',
];

/** @var ConfigResolverInterface */
private $configResolver;

/**
* @param ConfigResolverInterface $configResolver
*/
public function __construct(ConfigResolverInterface $configResolver)
{
$this->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;
}
}
39 changes: 27 additions & 12 deletions src/lib/Siteaccess/SiteaccessResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down

0 comments on commit 039b3db

Please sign in to comment.