Skip to content

Commit 61436fd

Browse files
author
Shikha Mishra
authored
Fixed #26118 Cms Block Scope wise value issue
1 parent 99f27bc commit 61436fd

File tree

1 file changed

+27
-3
lines changed
  • app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider

1 file changed

+27
-3
lines changed

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
use Magento\Cms\Api\BlockRepositoryInterface;
1111
use Magento\Cms\Api\Data\BlockInterface;
12+
use Magento\Framework\Api\SearchCriteriaBuilder;
1213
use Magento\Framework\Exception\NoSuchEntityException;
14+
use Magento\Store\Model\StoreManagerInterface;
1315
use Magento\Widget\Model\Template\FilterEmulate;
1416

1517
/**
@@ -26,17 +28,35 @@ class Block
2628
* @var FilterEmulate
2729
*/
2830
private $widgetFilter;
31+
32+
/**
33+
* @var \Magento\Framework\Api\SearchCriteriaBuilder
34+
*/
35+
protected $searchCriteriaBuilder;
36+
37+
/**
38+
* @var \Magento\Store\Model\StoreManagerInterface
39+
*/
40+
private $storeManager;
2941

3042
/**
3143
* @param BlockRepositoryInterface $blockRepository
3244
* @param FilterEmulate $widgetFilter
45+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
46+
* @param StoreManagerInterface $storeManager
3347
*/
3448
public function __construct(
3549
BlockRepositoryInterface $blockRepository,
36-
FilterEmulate $widgetFilter
50+
FilterEmulate $widgetFilter,
51+
SearchCriteriaBuilder $searchCriteriaBuilder = null,
52+
StoreManagerInterface $storeManager = null
3753
) {
3854
$this->blockRepository = $blockRepository;
3955
$this->widgetFilter = $widgetFilter;
56+
$this->searchCriteriaBuilder = $searchCriteriaBuilder ?: \Magento\Framework
57+
\App\ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
58+
$this->storeManager = $storeManager ?: \Magento\Framework
59+
\App\ObjectManager::getInstance()->get(StoreManagerInterface::class);
4060
}
4161

4262
/**
@@ -48,9 +68,13 @@ public function __construct(
4868
*/
4969
public function getData(string $blockIdentifier): array
5070
{
51-
$block = $this->blockRepository->getById($blockIdentifier);
71+
$searchCriteria = $this->searchCriteriaBuilder
72+
->addFilter('identifier', $blockIdentifier, 'eq')
73+
->addFilter('store_id', $this->storeManager->getStore()->getId(), 'eq')
74+
->addFilter('is_active', true, 'eq')->create();
75+
$block = current($this->blockRepository->getList($searchCriteria)->getItems());
5276

53-
if (false === $block->isActive()) {
77+
if (empty($block)) {
5478
throw new NoSuchEntityException(
5579
__('The CMS block with the "%1" ID doesn\'t exist.', $blockIdentifier)
5680
);

0 commit comments

Comments
 (0)