Skip to content

Commit 8ce6c77

Browse files
author
Bertrand Dunogier
committed
Exposed richtext embeds
``` { content { blogPost(id: 240) { body { html5 embeds { _info { id } ... on PlaceContent { name location { address } } } } } } } ```
1 parent 3a5ca49 commit 8ce6c77

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

GraphQL/Resolver/RichTextResolver.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
namespace BD\EzPlatformGraphQLBundle\GraphQL\Resolver;
77

88
use DOMDocument;
9+
use eZ\Publish\API\Repository\ContentService;
10+
use eZ\Publish\API\Repository\Values\Content\Relation;
911
use eZ\Publish\Core\FieldType\RichText\Converter as RichTextConverterInterface;
12+
use eZ\Publish\Core\FieldType\RichText;
1013

1114
class RichTextResolver
1215
{
@@ -19,10 +22,26 @@ class RichTextResolver
1922
*/
2023
private $richTextEditConverter;
2124

22-
public function __construct(RichTextConverterInterface $richTextConverter, RichTextConverterInterface $richTextEditConverter)
25+
/**
26+
* @var RichText\Type
27+
*/
28+
private $fieldType;
29+
/**
30+
* @var ContentService
31+
*/
32+
private $contentService;
33+
34+
public function __construct(
35+
RichTextConverterInterface $richTextConverter,
36+
RichTextConverterInterface $richTextEditConverter,
37+
ContentService $contentService,
38+
RichText\Type $fieldType
39+
)
2340
{
2441
$this->richTextConverter = $richTextConverter;
2542
$this->richTextEditConverter = $richTextEditConverter;
43+
$this->fieldType = $fieldType;
44+
$this->contentService = $contentService;
2645
}
2746

2847
public function xmlToHtml5(DOMDocument $document)
@@ -34,4 +53,12 @@ public function xmlToHtml5Edit(DOMDocument $document)
3453
{
3554
return $this->richTextEditConverter->convert($document)->saveHTML();
3655
}
56+
57+
public function resolveEmbeds(RichText\Value $value)
58+
{
59+
foreach ($this->fieldType->getRelations($value)[Relation::EMBED]['contentIds'] as $embeddedContentId) {
60+
// @todo Handle locationIds as well
61+
yield $this->contentService->loadContentInfo($embeddedContentId);
62+
}
63+
}
3764
}

Resources/config/graphql/Field.types.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ RichTextFieldValue:
390390
type: "String"
391391
description: "Editable HTML5 representation."
392392
resolve: "@=resolver('RichTextXmlToHtml5Edit', [value.xml])"
393+
deprecationReason: "Use 'rendered' with the html5_edit format argument"
394+
embeds:
395+
type: "[DomainContent]"
396+
description: "Content items embedded in this field"
397+
resolve: "@=resolver('RichTextEmbeds', [value.value])"
393398
inherits: [HTMLFieldValue]
394399

395400
SelectionFieldValue:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Url:
2+
type: object
3+
config:
4+
fields:
5+
id:
6+
type: ID
7+
builder: Relay::GlobalId
8+
href:
9+
type: String
10+
resolve: "@=value.url"
11+
isValid:
12+
type: Boolean
13+
lastChecked:
14+
type: DateTime
15+
created:
16+
type: DateTime
17+
modified:
18+
type: DateTime

Resources/config/resolvers.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,12 @@ services:
100100
arguments:
101101
- "@ezpublish.fieldType.ezrichtext.converter.output.xhtml5"
102102
- "@ezpublish.fieldType.ezrichtext.converter.edit.xhtml5"
103+
- '@ezpublish.siteaccessaware.service.content'
104+
- '@ezpublish.fieldType.ezrichtext'
103105
tags:
104106
- { name: overblog_graphql.resolver, alias: "RichTextXmlToHtml5", method: "xmlToHtml5" }
105107
- { name: overblog_graphql.resolver, alias: "RichTextXmlToHtml5Edit", method: "xmlToHtml5Edit" }
108+
- { name: overblog_graphql.resolver, alias: "RichTextEmbeds", method: "resolveEmbeds" }
106109

107110
BD\EzPlatformGraphQLBundle\GraphQL\Resolver\ImageFieldResolver:
108111
arguments:

0 commit comments

Comments
 (0)