Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 7a9b5bd

Browse files
author
Roman Glushko
committed
#31 Made it possible to return rendered content of CMS entities
1 parent dce6c11 commit 7a9b5bd

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Block.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Cms\Api\BlockRepositoryInterface;
1111
use Magento\Cms\Api\Data\BlockInterface;
1212
use Magento\Framework\Exception\NoSuchEntityException;
13+
use Magento\Widget\Model\Template\FilterEmulate;
1314

1415
/**
1516
* Cms block data provider
@@ -21,13 +22,21 @@ class Block
2122
*/
2223
private $blockRepository;
2324

25+
/**
26+
* @var FilterEmulate
27+
*/
28+
private $widgetFilter;
29+
2430
/**
2531
* @param BlockRepositoryInterface $blockRepository
32+
* @param FilterEmulate $widgetFilter
2633
*/
2734
public function __construct(
28-
BlockRepositoryInterface $blockRepository
35+
BlockRepositoryInterface $blockRepository,
36+
FilterEmulate $widgetFilter
2937
) {
3038
$this->blockRepository = $blockRepository;
39+
$this->widgetFilter = $widgetFilter;
3140
}
3241

3342
/**
@@ -43,10 +52,12 @@ public function getData(string $blockIdentifier): array
4352
throw new NoSuchEntityException();
4453
}
4554

55+
$renderedContent = $this->widgetFilter->filter($block->getContent());
56+
4657
$blockData = [
4758
BlockInterface::IDENTIFIER => $block->getIdentifier(),
4859
BlockInterface::TITLE => $block->getTitle(),
49-
BlockInterface::CONTENT => $block->getContent(),
60+
BlockInterface::CONTENT => $renderedContent,
5061
];
5162
return $blockData;
5263
}

app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Page.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,26 @@
1616
*/
1717
class Page
1818
{
19+
/**
20+
* @var FilterEmulate
21+
*/
22+
protected $widgetFilter;
23+
1924
/**
2025
* @var PageRepositoryInterface
2126
*/
22-
private $pageRepository;
27+
protected $pageRepository;
2328

2429
/**
2530
* @param PageRepositoryInterface $pageRepository
31+
* @param FilterEmulate $widgetFilter
2632
*/
2733
public function __construct(
28-
PageRepositoryInterface $pageRepository
34+
PageRepositoryInterface $pageRepository,
35+
FilterEmulate $widgetFilter
2936
) {
3037
$this->pageRepository = $pageRepository;
38+
$this->widgetFilter = $widgetFilter;
3139
}
3240

3341
/**
@@ -43,10 +51,12 @@ public function getData(int $pageId): array
4351
throw new NoSuchEntityException();
4452
}
4553

54+
$renderedContent = $this->widgetFilter->filter($page->getContent());
55+
4656
$pageData = [
4757
'url_key' => $page->getIdentifier(),
4858
PageInterface::TITLE => $page->getTitle(),
49-
PageInterface::CONTENT => $page->getContent(),
59+
PageInterface::CONTENT => $renderedContent,
5060
PageInterface::CONTENT_HEADING => $page->getContentHeading(),
5161
PageInterface::PAGE_LAYOUT => $page->getPageLayout(),
5262
PageInterface::META_TITLE => $page->getMetaTitle(),

0 commit comments

Comments
 (0)