Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion GraphQL/Resolver/RichTextResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
namespace BD\EzPlatformGraphQLBundle\GraphQL\Resolver;

use DOMDocument;
use eZ\Publish\API\Repository\ContentService;
use eZ\Publish\API\Repository\Values\Content\Relation;
use eZ\Publish\Core\FieldType\RichText\Converter as RichTextConverterInterface;
use eZ\Publish\Core\FieldType\RichText;

class RichTextResolver
{
Expand All @@ -19,10 +22,26 @@ class RichTextResolver
*/
private $richTextEditConverter;

public function __construct(RichTextConverterInterface $richTextConverter, RichTextConverterInterface $richTextEditConverter)
/**
* @var RichText\Type
*/
private $fieldType;
/**
* @var ContentService
*/
private $contentService;

public function __construct(
RichTextConverterInterface $richTextConverter,
RichTextConverterInterface $richTextEditConverter,
ContentService $contentService,
RichText\Type $fieldType
)
{
$this->richTextConverter = $richTextConverter;
$this->richTextEditConverter = $richTextEditConverter;
$this->fieldType = $fieldType;
$this->contentService = $contentService;
}

public function xmlToHtml5(DOMDocument $document)
Expand All @@ -34,4 +53,12 @@ public function xmlToHtml5Edit(DOMDocument $document)
{
return $this->richTextEditConverter->convert($document)->saveHTML();
}

public function resolveEmbeds(RichText\Value $value)
{
foreach ($this->fieldType->getRelations($value)[Relation::EMBED]['contentIds'] as $embeddedContentId) {
// @todo Handle locationIds as well
yield $this->contentService->loadContentInfo($embeddedContentId);
}
}
}
5 changes: 5 additions & 0 deletions Resources/config/graphql/Field.types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ RichTextFieldValue:
type: "String"
description: "Editable HTML5 representation."
resolve: "@=resolver('RichTextXmlToHtml5Edit', [value.xml])"
deprecationReason: "Use 'rendered' with the html5_edit format argument"
embeds:
type: "[DomainContent]"
description: "Content items embedded in this field"
resolve: "@=resolver('RichTextEmbeds', [value.value])"
inherits: [HTMLFieldValue]

SelectionFieldValue:
Expand Down
3 changes: 3 additions & 0 deletions Resources/config/resolvers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ services:
arguments:
- "@ezpublish.fieldType.ezrichtext.converter.output.xhtml5"
- "@ezpublish.fieldType.ezrichtext.converter.edit.xhtml5"
- '@ezpublish.siteaccessaware.service.content'
- '@ezpublish.fieldType.ezrichtext'
tags:
- { name: overblog_graphql.resolver, alias: "RichTextXmlToHtml5", method: "xmlToHtml5" }
- { name: overblog_graphql.resolver, alias: "RichTextXmlToHtml5Edit", method: "xmlToHtml5Edit" }
- { name: overblog_graphql.resolver, alias: "RichTextEmbeds", method: "resolveEmbeds" }

BD\EzPlatformGraphQLBundle\GraphQL\Resolver\ImageFieldResolver:
arguments:
Expand Down