Skip to content

Commit dc4842f

Browse files
author
Bertrand Dunogier
committed
Added '_url' field to content items
Returns the most prioritized url alias for the content item's main location.
1 parent ac3ad32 commit dc4842f

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

GraphQL/Resolver/DomainContentResolver.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ function (SearchHit $searchHit) {
120120
);
121121
}
122122

123+
public function resolveMainUrlAlias(ContentInfo $contentInfo)
124+
{
125+
$aliases = $this->repository->getURLAliasService()->listLocationAliases(
126+
$this->getLocationService()->loadLocation($contentInfo->mainLocationId),
127+
false
128+
);
129+
130+
return isset($aliases[0]->path) ? $aliases[0]->path : null;
131+
}
132+
123133
public function resolveDomainFieldValue($contentInfo, $fieldDefinitionIdentifier)
124134
{
125135
$content = $this->getContentService()->loadContent($contentInfo->id);

Resources/config/graphql/DomainContent.types.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ DomainContent:
2424
_name:
2525
description: "The content item's name, in the prioritized language(s), based on the object name pattern"
2626
type: String
27+
_url:
28+
description: "The content item's url alias, based on the main location."
29+
type: String
2730
resolveType: "@=resolver('DomainContentType', [value])"
2831

2932
AbstractDomainContent:
@@ -59,6 +62,10 @@ AbstractDomainContent:
5962
description: "The content item's name, in the prioritized language(s), based on the object name pattern"
6063
type: String
6164
resolve: "@=resolver('ContentName', [value])"
65+
_url:
66+
description: "The content item's url alias, based on the main location."
67+
type: String
68+
resolve: "@=resolver('MainUrlAlias', [value])"
6269

6370
# @todo interface ?
6471
DomainContentTypeGroup:

Resources/config/resolvers.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ services:
4545
- { name: overblog_graphql.resolver, alias: "DomainContentItem", method: "resolveDomainContentItem" }
4646
- { name: overblog_graphql.resolver, alias: "DomainRelationFieldValue", method: "resolveDomainRelationFieldValue" }
4747
- { name: overblog_graphql.resolver, alias: "ContentName", method: "resolveContentName" }
48+
- { name: overblog_graphql.resolver, alias: "MainUrlAlias", method: "resolveMainUrlAlias" }
4849
arguments:
4950
$repository: "@ezpublish.siteaccessaware.repository"
5051

0 commit comments

Comments
 (0)