-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved the LocationGuesser API to be usable for relations as well
Two ItemFactory instances are exposed, depending on the need: - $siteItemFactory: locations and aliases are within the current site root only - $relatedItemFactory: locations and aliases can be in other public siteaccesses / site roots
- Loading branch information
Bertrand Dunogier
committed
Nov 27, 2020
1 parent
26ee4f0
commit 6eb2633
Showing
8 changed files
with
140 additions
and
22 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/GraphQL/Resolver/LocationGuesser/AllAllowedLocationProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?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\EzPlatformGraphQL\GraphQL\Resolver\LocationGuesser; | ||
|
||
use eZ\Publish\API\Repository\LocationService; | ||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
|
||
/** | ||
* Returns all the locations the current user has access to. | ||
*/ | ||
class AllAllowedLocationProvider implements LocationProvider | ||
{ | ||
/** | ||
* @var \eZ\Publish\API\Repository\LocationService | ||
*/ | ||
private $locationService; | ||
|
||
public function __construct(LocationService $locationService) | ||
{ | ||
$this->locationService = $locationService; | ||
} | ||
|
||
public function getLocations(Content $content): LocationList | ||
{ | ||
$list = new LocationList($content); | ||
|
||
foreach ($this->locationService->loadLocations($content->contentInfo) as $location) { | ||
$list->addLocation($location); | ||
} | ||
|
||
return $list; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/GraphQL/Resolver/LocationGuesser/CurrentSiteLocationProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?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\EzPlatformGraphQL\GraphQL\Resolver\LocationGuesser; | ||
|
||
use eZ\Publish\API\Repository\SearchService; | ||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
use eZ\Publish\API\Repository\Values\Content\LocationQuery; | ||
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; | ||
use EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\ContentCollectionFilterBuilder; | ||
|
||
/** | ||
* Returns the locations from the current site (e.g. within its tree root) | ||
*/ | ||
class CurrentSiteLocationProvider implements LocationProvider | ||
{ | ||
/** | ||
* @var \eZ\Publish\API\Repository\SearchService | ||
*/ | ||
private $searchService; | ||
/** | ||
* @var \EzSystems\EzPlatformGraphQL\GraphQL\InputMapper\ContentCollectionFilterBuilder | ||
*/ | ||
private $filterBuilder; | ||
|
||
public function __construct(SearchService $searchService, ContentCollectionFilterBuilder $filterBuilder) | ||
{ | ||
$this->searchService = $searchService; | ||
$this->filterBuilder = $filterBuilder; | ||
} | ||
|
||
public function getLocations(Content $content): LocationList | ||
{ | ||
$query = new LocationQuery([ | ||
'filter' => new Criterion\LogicalAnd([ | ||
$this->filterBuilder->buildFilter(), | ||
new Criterion\ContentId($content->id) | ||
]) | ||
]); | ||
|
||
$list = new LocationList($content); | ||
foreach ($this->searchService->findLocations($query)->searchHits as $searchHit) { | ||
$list->addLocation($searchHit->valueObject); | ||
} | ||
|
||
return $list; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?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. | ||
*/ | ||
|
||
namespace EzSystems\EzPlatformGraphQL\GraphQL\Resolver\LocationGuesser; | ||
|
||
use eZ\Publish\API\Repository\Values\Content\Content; | ||
|
||
interface LocationProvider | ||
{ | ||
public function getLocations(Content $content): LocationList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters