From b6f494664893fdf869755f8a98bae5ec7c6b4897 Mon Sep 17 00:00:00 2001 From: dfritschy Date: Wed, 23 Oct 2019 16:27:43 +0200 Subject: [PATCH 1/2] GraphQL query support for ezxml field type --- bundle/GraphQL/Resolver/XmlTextResolver.php | 31 +++++++++++++++++++ bundle/Resources/config/default_settings.yml | 4 +++ .../Resources/config/graphql/Field.types.yml | 20 ++++++++++++ bundle/Resources/config/services.yml | 7 +++++ 4 files changed, 62 insertions(+) create mode 100644 bundle/GraphQL/Resolver/XmlTextResolver.php create mode 100644 bundle/Resources/config/graphql/Field.types.yml diff --git a/bundle/GraphQL/Resolver/XmlTextResolver.php b/bundle/GraphQL/Resolver/XmlTextResolver.php new file mode 100644 index 00000000..f8d5c713 --- /dev/null +++ b/bundle/GraphQL/Resolver/XmlTextResolver.php @@ -0,0 +1,31 @@ +xmlTextConverter = $xmlTextConverter; + } + + public function xmlTextToHtml5(DOMDocument $document) + { + return $this->xmlTextConverter->convert($document); + } +} diff --git a/bundle/Resources/config/default_settings.yml b/bundle/Resources/config/default_settings.yml index 769500f0..067d1fd6 100644 --- a/bundle/Resources/config/default_settings.yml +++ b/bundle/Resources/config/default_settings.yml @@ -8,3 +8,7 @@ parameters: - path: "%kernel.root_dir%/../vendor/ezsystems/ezplatform-xmltext-fieldtype/lib/FieldType/XmlText/Input/Resources/stylesheets/eZXml2Html5_custom.xsl" priority: 0 + + ezplatform_graphql.schema.content.mapping.field_definition_type: + ezxmltext: + value_type: XmlTextFieldValue diff --git a/bundle/Resources/config/graphql/Field.types.yml b/bundle/Resources/config/graphql/Field.types.yml new file mode 100644 index 00000000..b2a41809 --- /dev/null +++ b/bundle/Resources/config/graphql/Field.types.yml @@ -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])" diff --git a/bundle/Resources/config/services.yml b/bundle/Resources/config/services.yml index 33dd729a..cb2503db 100644 --- a/bundle/Resources/config/services.yml +++ b/bundle/Resources/config/services.yml @@ -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" } From b795bce2f621c46668f501604d40bd5bbe12e0a7 Mon Sep 17 00:00:00 2001 From: dfritschy Date: Thu, 24 Oct 2019 17:11:48 +0200 Subject: [PATCH 2/2] Replaced settings by using a compiler pass adding the mapping --- .../Compiler/XmlTextGraphqlSchemaPass.php | 30 +++++++++++++++++++ ...ystemsEzPlatformXmlTextFieldTypeBundle.php | 2 ++ bundle/Resources/config/default_settings.yml | 4 --- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 bundle/DependencyInjection/Compiler/XmlTextGraphqlSchemaPass.php diff --git a/bundle/DependencyInjection/Compiler/XmlTextGraphqlSchemaPass.php b/bundle/DependencyInjection/Compiler/XmlTextGraphqlSchemaPass.php new file mode 100644 index 00000000..3cd8f728 --- /dev/null +++ b/bundle/DependencyInjection/Compiler/XmlTextGraphqlSchemaPass.php @@ -0,0 +1,30 @@ +hasParameter(self::SCHEMA_FIELD_TYPES) ? $container->getParameter(self::SCHEMA_FIELD_TYPES) : []; + + $graphqlSchemaDef['ezxmltext'] = ['value_type' => 'XmlTextFieldValue']; + $container->setParameter(self::SCHEMA_FIELD_TYPES, $graphqlSchemaDef); + } +} diff --git a/bundle/EzSystemsEzPlatformXmlTextFieldTypeBundle.php b/bundle/EzSystemsEzPlatformXmlTextFieldTypeBundle.php index 6eebb05e..ac93f0c0 100644 --- a/bundle/EzSystemsEzPlatformXmlTextFieldTypeBundle.php +++ b/bundle/EzSystemsEzPlatformXmlTextFieldTypeBundle.php @@ -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; @@ -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 diff --git a/bundle/Resources/config/default_settings.yml b/bundle/Resources/config/default_settings.yml index 067d1fd6..769500f0 100644 --- a/bundle/Resources/config/default_settings.yml +++ b/bundle/Resources/config/default_settings.yml @@ -8,7 +8,3 @@ parameters: - path: "%kernel.root_dir%/../vendor/ezsystems/ezplatform-xmltext-fieldtype/lib/FieldType/XmlText/Input/Resources/stylesheets/eZXml2Html5_custom.xsl" priority: 0 - - ezplatform_graphql.schema.content.mapping.field_definition_type: - ezxmltext: - value_type: XmlTextFieldValue