-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dmitrijs-voronovs/cmsBlocks-fix
Cms blocks fix
- Loading branch information
Showing
3 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* ScandiPWA_CmsGraphQl | ||
* | ||
* @category Scandiweb | ||
* @package ScandiPWA_CmsGraphQl | ||
* @copyright Copyright (c) 2018 Scandiweb, Ltd (https://scandiweb.com) | ||
*/ | ||
|
||
namespace ScandiPWA\CmsGraphQl\Model\Resolver\DataProvider; | ||
|
||
use Magento\Cms\Api\BlockRepositoryInterface; | ||
use Magento\Cms\Api\Data\BlockInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Widget\Model\Template\FilterEmulate; | ||
|
||
/** | ||
* Class Block | ||
* @package ScandiPWA\CmsGraphQl\Model\Resolver\DataProvider | ||
*/ | ||
class Block extends \Magento\CmsGraphQl\Model\Resolver\DataProvider\Block | ||
{ | ||
/** | ||
* @var BlockRepositoryInterface | ||
*/ | ||
private $blockRepository; | ||
|
||
/** | ||
* @var FilterEmulate | ||
*/ | ||
private $widgetFilter; | ||
|
||
/** | ||
* @param BlockRepositoryInterface $blockRepository | ||
* @param FilterEmulate $widgetFilter | ||
*/ | ||
public function __construct( | ||
BlockRepositoryInterface $blockRepository, | ||
FilterEmulate $widgetFilter | ||
) { | ||
$this->blockRepository = $blockRepository; | ||
$this->widgetFilter = $widgetFilter; | ||
} | ||
|
||
/** | ||
* Get block data | ||
* | ||
* @param string $blockIdentifier | ||
* @return array | ||
* @throws NoSuchEntityException | ||
*/ | ||
public function getData(string $blockIdentifier): array | ||
{ | ||
$block = $this->blockRepository->getById($blockIdentifier); | ||
|
||
if (!$block->isActive()) { | ||
return [ | ||
BlockInterface::IDENTIFIER => $block->getIdentifier(), | ||
'disabled' => true | ||
]; | ||
} | ||
|
||
$renderedContent = $this->widgetFilter->filter($block->getContent()); | ||
|
||
return [ | ||
BlockInterface::IDENTIFIER => $block->getIdentifier(), | ||
BlockInterface::TITLE => $block->getTitle(), | ||
BlockInterface::CONTENT => $renderedContent, | ||
'disabled' => false | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?xml version="1.0"?> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<preference for="Magento\CmsGraphQl\Model\Resolver\Page" type="ScandiPWA\CmsGraphQl\Model\Resolver\Page"/> | ||
<preference for="Magento\CmsGraphQl\Model\Resolver\DataProvider\Block" type="ScandiPWA\CmsGraphQl\Model\Resolver\DataProvider\Block"/> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters