Skip to content

Commit

Permalink
GraphQL-176: Show only active CMS Blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriy Nayda committed Nov 22, 2018
1 parent 5c6f20f commit 922d398
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
27 changes: 6 additions & 21 deletions app/code/Magento/CmsGraphQl/Model/Resolver/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Psr\Log\LoggerInterface;

/**
* CMS blocks field resolver, used for GraphQL request processing
Expand All @@ -26,20 +25,13 @@ class Blocks implements ResolverInterface
*/
private $blockDataProvider;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param BlockDataProvider $blockDataProvider
*/
public function __construct(
BlockDataProvider $blockDataProvider,
LoggerInterface $logger
BlockDataProvider $blockDataProvider
) {
$this->blockDataProvider = $blockDataProvider;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -84,19 +76,12 @@ private function getBlockIdentifiers(array $args): array
private function getBlocksData(array $blockIdentifiers): array
{
$blocksData = [];
try {
foreach ($blockIdentifiers as $blockIdentifier) {
$blockData = $this->blockDataProvider->getData($blockIdentifier);
if (!empty($blockData)) {
$blocksData[$blockIdentifier] = $blockData;
} else {
$this->logger->warning(
sprintf('The CMS block with the "%s" Identifier is disabled.', $blockIdentifier)
);
}
foreach ($blockIdentifiers as $blockIdentifier) {
try {
$blocksData[$blockIdentifier] = $this->blockDataProvider->getData($blockIdentifier);
} catch (NoSuchEntityException $e) {
$blocksData[$blockIdentifier] = new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
}
} catch (NoSuchEntityException $e) {
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
}
return $blocksData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function getData(string $blockIdentifier): array
$block = $this->blockRepository->getById($blockIdentifier);

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

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

0 comments on commit 922d398

Please sign in to comment.