For this issue please apply below Patch (feel free to give your thoughts to improve the solution):
**FOR MAGENTO 2.3.3**
Index: vendor/magento/module-cms-graph-ql/Model/Resolver/DataProvider/Block.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- /vendor/magento/module-cms-graph-ql/Model/Resolver/DataProvider/Block.php (date 1579789952704)
+++ /vendor/magento/module-cms-graph-ql/Model/Resolver/DataProvider/Block.php (date 1579789952704)
@@ -11,6 +11,8 @@
use Magento\Cms\Api\Data\BlockInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Widget\Model\Template\FilterEmulate;
+use Magento\Store\Model\StoreManagerInterface;
+use Magento\Cms\Api\GetBlockByIdentifierInterface as BlockGetter;
/**
* Cms block data provider
@@ -33,10 +35,14 @@
*/
public function __construct(
BlockRepositoryInterface $blockRepository,
- FilterEmulate $widgetFilter
+ FilterEmulate $widgetFilter,
+ StoreManagerInterface $storeManager,
+ BlockGetter $BlockGetter
) {
$this->blockRepository = $blockRepository;
$this->widgetFilter = $widgetFilter;
+ $this->storeManager = $storeManager;
+ $this->blockGetter = $BlockGetter;
}
/**
@@ -48,22 +54,25 @@
*/
public function getData(string $blockIdentifier): array
{
- $block = $this->blockRepository->getById($blockIdentifier);
-
+ /* start custom code changes to get cms based on store */
+ $storeId = (int)$this->storeManager->getStore()->getId();
+ $block = $this->blockGetter->execute($blockIdentifier, $storeId);
+ /* end custom code changes to get cms based on store */
if (false === $block->isActive()) {
throw new NoSuchEntityException(
__('The CMS block with the "%1" ID doesn\'t exist.', $blockIdentifier)
);
}
-
- $renderedContent = $this->widgetFilter->filter($block->getContent());
-
- $blockData = [
- BlockInterface::BLOCK_ID => $block->getId(),
- BlockInterface::IDENTIFIER => $block->getIdentifier(),
- BlockInterface::TITLE => $block->getTitle(),
- BlockInterface::CONTENT => $renderedContent,
- ];
- return $blockData;
- }
-}
+ if($block->getIdentifier() == $blockIdentifier) {
+ $renderedContent = $this->widgetFilter->filter($block->getContent());
+ $blockData = [
+ BlockInterface::BLOCK_ID => $block->getId(),
+ BlockInterface::IDENTIFIER => $block->getIdentifier(),
+ BlockInterface::TITLE => $block->getTitle(),
+ BlockInterface::CONTENT => $renderedContent,
+ ];
+ return $blockData;
+ }
+ return '';
+ }
+}
\ No newline at end of file
FOR MAGENTO 2.3.4
Index: /vendor/magento/module-cms-graph-ql/Model/Resolver/DataProvider/Block.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- /vendor/magento/module-cms-graph-ql/Model/Resolver/DataProvider/Block.php (date 1579875025862)
+++ /vendor/magento/module-cms-graph-ql/Model/Resolver/DataProvider/Block.php (date 1579875025862)
@@ -11,6 +11,8 @@
use Magento\Cms\Api\Data\BlockInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Widget\Model\Template\FilterEmulate;
+use Magento\Store\Model\StoreManagerInterface;
+use Magento\Cms\Api\GetBlockByIdentifierInterface as BlockGetter;
/**
* Cms block data provider
@@ -30,13 +32,19 @@
/**
* @param BlockRepositoryInterface $blockRepository
* @param FilterEmulate $widgetFilter
+ * @param StoreManagerInterface $storeManager
+ * @param BlockGetter $BlockGetter
*/
public function __construct(
BlockRepositoryInterface $blockRepository,
- FilterEmulate $widgetFilter
+ FilterEmulate $widgetFilter,
+ StoreManagerInterface $storeManager,
+ BlockGetter $BlockGetter
) {
$this->blockRepository = $blockRepository;
$this->widgetFilter = $widgetFilter;
+ $this->storeManager = $storeManager;
+ $this->blockGetter = $BlockGetter;
}
/**
@@ -48,7 +56,10 @@
*/
public function getData(string $blockIdentifier): array
{
- $block = $this->blockRepository->getById($blockIdentifier);
+ /* start custom code changes to get cms based on store */
+ $storeId = (int)$this->storeManager->getStore()->getId();
+ $block = $this->blockGetter->execute($blockIdentifier, $storeId);
+ /* end custom code changes to get cms based on store */
if (false === $block->isActive()) {
throw new NoSuchEntityException(
@@ -57,13 +68,16 @@
}
$renderedContent = $this->widgetFilter->filterDirective($block->getContent());
-
- $blockData = [
- BlockInterface::BLOCK_ID => $block->getId(),
- BlockInterface::IDENTIFIER => $block->getIdentifier(),
- BlockInterface::TITLE => $block->getTitle(),
- BlockInterface::CONTENT => $renderedContent,
- ];
- return $blockData;
+ if ($block->getIdentifier() == $blockIdentifier) {
+ $blockData = [
+ BlockInterface::BLOCK_ID => $block->getId(),
+ BlockInterface::IDENTIFIER => $block->getIdentifier(),
+ BlockInterface::TITLE => $block->getTitle(),
+ BlockInterface::CONTENT => $renderedContent,
+ ];
+ return $blockData;
+ }else{
+ return [];
+ }
}
}