Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GetBlockByIdentifier.php
Go to the documentation of this file.
1 <?php
7 namespace Magento\Cms\Model;
8 
12 
17 {
21  private $blockFactory;
22 
26  private $blockResource;
27 
32  public function __construct(
33  \Magento\Cms\Model\BlockFactory $blockFactory,
34  \Magento\Cms\Model\ResourceModel\Block $blockResource
35  ) {
36  $this->blockFactory = $blockFactory;
37  $this->blockResource = $blockResource;
38  }
39 
43  public function execute(string $identifier, int $storeId) : BlockInterface
44  {
45  $block = $this->blockFactory->create();
46  $block->setStoreId($storeId);
47  $this->blockResource->load($block, $identifier, BlockInterface::IDENTIFIER);
48 
49  if (!$block->getId()) {
50  throw new NoSuchEntityException(__('The CMS block with the "%1" ID doesn\'t exist.', $identifier));
51  }
52 
53  return $block;
54  }
55 }
__()
Definition: __.php:13
$block
Definition: block.php:8
__construct(\Magento\Cms\Model\BlockFactory $blockFactory, \Magento\Cms\Model\ResourceModel\Block $blockResource)
execute(string $identifier, int $storeId)