Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Block.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
18 class Block
19 {
23  private $blockRepository;
24 
28  private $widgetFilter;
29 
34  public function __construct(
35  BlockRepositoryInterface $blockRepository,
36  FilterEmulate $widgetFilter
37  ) {
38  $this->blockRepository = $blockRepository;
39  $this->widgetFilter = $widgetFilter;
40  }
41 
47  public function getData(string $blockIdentifier): array
48  {
49  $block = $this->blockRepository->getById($blockIdentifier);
50 
51  if (false === $block->isActive()) {
52  throw new NoSuchEntityException();
53  }
54 
55  $renderedContent = $this->widgetFilter->filter($block->getContent());
56 
57  $blockData = [
58  BlockInterface::IDENTIFIER => $block->getIdentifier(),
59  BlockInterface::TITLE => $block->getTitle(),
60  BlockInterface::CONTENT => $renderedContent,
61  ];
62  return $blockData;
63  }
64 }
$blockRepository
$block
Definition: block.php:8
__construct(BlockRepositoryInterface $blockRepository, FilterEmulate $widgetFilter)
Definition: Block.php:34