Skip to content

Commit

Permalink
Merge pull request #1 from dmitrijs-voronovs/cmsBlocks-fix
Browse files Browse the repository at this point in the history
Cms blocks fix
  • Loading branch information
alfredsgenkins authored Sep 9, 2019
2 parents 5599c6c + 9e1a5fc commit 5e99475
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
72 changes: 72 additions & 0 deletions src/Model/Resolver/DataProvider/Block.php
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
];
}
}
1 change: 1 addition & 0 deletions src/etc/di.xml
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>
6 changes: 5 additions & 1 deletion src/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ type Query {
id: Int @doc(description: "Id of the CMS page")
url_key: String @doc(description: "Url key of the CMS page")
): CmsPage @resolver(class: "Magento\\CmsGraphQl\\Model\\Resolver\\Page") @doc(description: "The CMS page query returns information about a CMS page")
}
}

type CmsBlock @doc(description: "CMS block defines all CMS block information") {
disabled: Boolean @doc(description: "CMS block is disabled")
}

0 comments on commit 5e99475

Please sign in to comment.