Skip to content

Commit 922d398

Browse files
author
Valeriy Nayda
committed
GraphQL-176: Show only active CMS Blocks
1 parent 5c6f20f commit 922d398

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

app/code/Magento/CmsGraphQl/Model/Resolver/Blocks.php

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1515
use Magento\Framework\GraphQl\Query\ResolverInterface;
1616
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17-
use Psr\Log\LoggerInterface;
1817

1918
/**
2019
* CMS blocks field resolver, used for GraphQL request processing
@@ -26,20 +25,13 @@ class Blocks implements ResolverInterface
2625
*/
2726
private $blockDataProvider;
2827

29-
/**
30-
* @var LoggerInterface
31-
*/
32-
private $logger;
33-
3428
/**
3529
* @param BlockDataProvider $blockDataProvider
3630
*/
3731
public function __construct(
38-
BlockDataProvider $blockDataProvider,
39-
LoggerInterface $logger
32+
BlockDataProvider $blockDataProvider
4033
) {
4134
$this->blockDataProvider = $blockDataProvider;
42-
$this->logger = $logger;
4335
}
4436

4537
/**
@@ -84,19 +76,12 @@ private function getBlockIdentifiers(array $args): array
8476
private function getBlocksData(array $blockIdentifiers): array
8577
{
8678
$blocksData = [];
87-
try {
88-
foreach ($blockIdentifiers as $blockIdentifier) {
89-
$blockData = $this->blockDataProvider->getData($blockIdentifier);
90-
if (!empty($blockData)) {
91-
$blocksData[$blockIdentifier] = $blockData;
92-
} else {
93-
$this->logger->warning(
94-
sprintf('The CMS block with the "%s" Identifier is disabled.', $blockIdentifier)
95-
);
96-
}
79+
foreach ($blockIdentifiers as $blockIdentifier) {
80+
try {
81+
$blocksData[$blockIdentifier] = $this->blockDataProvider->getData($blockIdentifier);
82+
} catch (NoSuchEntityException $e) {
83+
$blocksData[$blockIdentifier] = new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
9784
}
98-
} catch (NoSuchEntityException $e) {
99-
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
10085
}
10186
return $blocksData;
10287
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ public function getData(string $blockIdentifier): array
4949
$block = $this->blockRepository->getById($blockIdentifier);
5050

5151
if (false === $block->isActive()) {
52-
return [];
52+
throw new NoSuchEntityException(
53+
__('The CMS block with the "%1" ID doesn\'t exist.', $blockIdentifier)
54+
);
5355
}
5456

5557
$renderedContent = $this->widgetFilter->filter($block->getContent());

0 commit comments

Comments
 (0)