From dd7869083524a1f8a99b52895e14d5c88d33cca2 Mon Sep 17 00:00:00 2001 From: Peter van der Wal Date: Fri, 4 Aug 2023 15:34:06 +0200 Subject: [PATCH] feat: include 'frontend' field for Wysiwyg Editables To be able to retrieve the processed HTML where Pimcore Element links are rewritten where necessary. --- .../04_Query/01_Document_Queries.md | 45 +++++++++++++++++++ .../DocumentElementType/WysiwygType.php | 9 ++++ 2 files changed, 54 insertions(+) diff --git a/doc/10_GraphQL/04_Query/01_Document_Queries.md b/doc/10_GraphQL/04_Query/01_Document_Queries.md index de25bfd2..689d50be 100644 --- a/doc/10_GraphQL/04_Query/01_Document_Queries.md +++ b/doc/10_GraphQL/04_Query/01_Document_Queries.md @@ -69,6 +69,51 @@ } ``` +### Fetch Document Page and get processed Wysiwyg editable content + +* Field `text` contains the HTML as it is stored in Pimcore for this Wysiwyg editable. +* Field `frontend` contain the processed HTML where Pimcore Element links are rewritten where necessary. + +```graphql +{ + getDocument(id: 207) { + ... on document_page { + id, + editables(getInheritedValues: true){ + __typename + ...on document_editableWysiwyg { + text + frontend + } + } + } + } +} +``` + +### Fetch Full Rendered Document Page + +The `rendered` field can be used to retrieve a rendered version of the page. Available options: +* `attributes`: Attributes passed into the controller/action +* `query`: Query Params passed into the controller/action +* `options`: Options passed into the renderer +* `use_layout`: Enable/disable Layout Rendering + +```graphql +{ + getDocument(id: 207) { + ... on document_page { + id, + rendered( + attributes: [{key: "myControllerAttributeName", value: "Hello World!"}], + use_layout: true, + options: [{key: "ignore_errors", value: "1"}] + ) + } + } +} +``` + ## Fetch Document Page via Data Object Relation and Get More Editable Data * get data object ID 61 diff --git a/src/GraphQL/DocumentElementType/WysiwygType.php b/src/GraphQL/DocumentElementType/WysiwygType.php index 35823d14..fce1c6bd 100644 --- a/src/GraphQL/DocumentElementType/WysiwygType.php +++ b/src/GraphQL/DocumentElementType/WysiwygType.php @@ -15,6 +15,9 @@ namespace Pimcore\Bundle\DataHubBundle\GraphQL\DocumentElementType; +use GraphQL\Type\Definition\Type; +use Pimcore\Model\Document\Editable\Wysiwyg; + class WysiwygType extends SimpleTextType { protected static $instance; @@ -26,6 +29,12 @@ public static function getInstance() { if (!self::$instance) { $config = self::getStandardConfig('document_editableWysiwyg'); + + $config['fields']['frontend'] = [ + 'type' => Type::string(), + 'resolve' => static fn (Wysiwyg $value) => $value->frontend(), + ]; + self::$instance = new static($config); }