Skip to content

Commit

Permalink
feat: include 'frontend' field for Wysiwyg Editables
Browse files Browse the repository at this point in the history
To be able to retrieve the processed HTML where Pimcore Element links are rewritten where necessary.
  • Loading branch information
youwe-petervanderwal committed Aug 4, 2023
1 parent dc9862d commit 136a691
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
45 changes: 45 additions & 0 deletions doc/10_GraphQL/04_Query/01_Document_Queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/GraphQL/DocumentElementType/WysiwygType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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): ?string => $value->frontend(),

Check failure on line 35 in src/GraphQL/DocumentElementType/WysiwygType.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.0, lowest, false)

Anonymous function never returns null so it can be removed from the return type.

Check failure on line 35 in src/GraphQL/DocumentElementType/WysiwygType.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, highest, true)

Anonymous function never returns null so it can be removed from the return type.

Check failure on line 35 in src/GraphQL/DocumentElementType/WysiwygType.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.2, highest, 11.x-dev as 11.0.0, true, true)

Anonymous function never returns null so it can be removed from the return type.
];

self::$instance = new static($config);
}

Expand Down

0 comments on commit 136a691

Please sign in to comment.