Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BlockFactory.php
Go to the documentation of this file.
1 <?php
7 
9 
17 {
23  protected $objectManager;
24 
31  {
32  $this->objectManager = $objectManager;
33  }
34 
43  public function createBlock($blockName, array $arguments = [])
44  {
45  $blockName = ltrim($blockName, '\\');
46  $block = $this->objectManager->create($blockName, $arguments);
47  if (!$block instanceof BlockInterface) {
48  throw new \LogicException($blockName . ' does not implement BlockInterface');
49  }
50  if ($block instanceof Template) {
51  $block->setTemplateContext($block);
52  }
53  return $block;
54  }
55 }
__construct(ObjectManagerInterface $objectManager)
createBlock($blockName, array $arguments=[])
$block
Definition: block.php:8
$arguments