Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraphQL query support for ezxmltext field type #111

Open
wants to merge 3 commits into
base: 1.9
Choose a base branch
from
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
30 changes: 30 additions & 0 deletions bundle/DependencyInjection/Compiler/XmlTextGraphqlSchemaPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* This file is part of the eZ Platform XmlText Field Type package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*
* @version //autogentag//
*/
namespace EzSystems\EzPlatformXmlTextFieldTypeBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Compiler pass adding GraphQL schema mapping for ezxmltext field type.
*/
class XmlTextGraphqlSchemaPass implements CompilerPassInterface
{
private const SCHEMA_FIELD_TYPES = 'ezplatform_graphql.schema.content.mapping.field_definition_type';

public function process(ContainerBuilder $container)
{
$graphqlSchemaDef = $container->hasParameter(self::SCHEMA_FIELD_TYPES) ? $container->getParameter(self::SCHEMA_FIELD_TYPES) : [];

$graphqlSchemaDef['ezxmltext'] = ['value_type' => 'XmlTextFieldValue'];
$container->setParameter(self::SCHEMA_FIELD_TYPES, $graphqlSchemaDef);
}
}
2 changes: 2 additions & 0 deletions bundle/EzSystemsEzPlatformXmlTextFieldTypeBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace EzSystems\EzPlatformXmlTextFieldTypeBundle;

use EzSystems\EzPlatformXmlTextFieldTypeBundle\DependencyInjection\Compiler\XmlTextConverterPass;
use EzSystems\EzPlatformXmlTextFieldTypeBundle\DependencyInjection\Compiler\XmlTextGraphqlSchemaPass;
use EzSystems\EzPlatformXmlTextFieldTypeBundle\DependencyInjection\Configuration\Parser as ConfigParser;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -22,6 +23,7 @@ public function build(ContainerBuilder $container)
parent::build($container);

$container->addCompilerPass(new XmlTextConverterPass());
$container->addCompilerPass(new XmlTextGraphqlSchemaPass());

/**
* @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension
Expand Down
31 changes: 31 additions & 0 deletions bundle/GraphQL/Resolver/XmlTextResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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\EzPlatformXmlTextFieldTypeBundle\GraphQL\Resolver;

use DOMDocument;
use eZ\Publish\Core\FieldType\XmlText\Converter\Html5 as Html5Converter;

/**
* @internal
*/
class XmlTextResolver
{
/**
* @var Html5Converter
*/
private $xmlTextConverter;

public function __construct(Html5Converter $xmlTextConverter)
{
$this->xmlTextConverter = $xmlTextConverter;
}

public function xmlTextToHtml5(DOMDocument $document)
{
return $this->xmlTextConverter->convert($document);
}
}
20 changes: 20 additions & 0 deletions bundle/Resources/config/graphql/Field.types.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
XmlTextFieldValue:
type: object
config:
fields:
text:
type: "String"
description: "String representation of the value"
resolve: "@=value"
xml:
type: "String"
description: "The raw xml"
resolve: "@=value"
plaintext:
type: "String"
description: "Plain text representation of the value, without tags. Warning: the text representation may not be perfect."
resolve: "@=value.xml.textContent"
html5:
type: "String"
description: "HTML5 representation."
resolve: "@=resolver('XmlTextToHtml5', [value.xml])"
7 changes: 7 additions & 0 deletions bundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ services:
- "@ezpublish.api.repository"
- "@?logger"
- "@ezpublish.fieldType.ezrichtext.validator.docbook"

ezxmltext.graphql.resolver:
class: EzSystems\EzPlatformXmlTextFieldTypeBundle\GraphQL\Resolver\XmlTextResolver
arguments:
- "@ezpublish.fieldType.ezxmltext.converter.html5"
tags:
- { name: overblog_graphql.resolver, alias: "XmlTextToHtml5", method: "xmlTextToHtml5" }