1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- declare(strict_types=1);
- namespace Magento\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;
- /**
- * Cms block data provider
- */
- class 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 (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::IDENTIFIER => $block->getIdentifier(),
- BlockInterface::TITLE => $block->getTitle(),
- BlockInterface::CONTENT => $renderedContent,
- ];
- return $blockData;
- }
- }
|