Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Magento 2.3.2 - PWA - graphQl fetching Issue for phtml file called in static block #960 #971

Merged
merged 5 commits into from
Oct 31, 2019
29 changes: 27 additions & 2 deletions app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Cms\Api\Data\BlockInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Widget\Model\Template\FilterEmulate;
use Magento\Framework\App\State;

/**
* Cms block data provider
Expand All @@ -27,16 +28,24 @@ class Block
*/
private $widgetFilter;

/**
* @var State
*/
private $state;

/**
* @param BlockRepositoryInterface $blockRepository
* @param FilterEmulate $widgetFilter
* @param State $state
*/
public function __construct(
BlockRepositoryInterface $blockRepository,
FilterEmulate $widgetFilter
FilterEmulate $widgetFilter,
State $state
) {
$this->blockRepository = $blockRepository;
$this->widgetFilter = $widgetFilter;
$this->state = $state;
}

/**
Expand All @@ -56,7 +65,11 @@ public function getData(string $blockIdentifier): array
);
}

$renderedContent = $this->widgetFilter->filter($block->getContent());
$renderedContent = $this->state->emulateAreaCode(
\Magento\Framework\App\Area::AREA_FRONTEND,
[$this, 'getRenderedBlockContent'],
[$block->getContent()]
);

$blockData = [
BlockInterface::BLOCK_ID => $block->getId(),
Expand All @@ -66,4 +79,16 @@ public function getData(string $blockIdentifier): array
];
return $blockData;
}

/**
* Get block data as it rendered on frontend
*
* @param string $blockContent
*
* @return string
*/
public function getRenderedBlockContent(string $blockContent) : string
{
return $this->widgetFilter->filter($blockContent);
}
}