Esempio n. 1
0
 /**
  * Get render instance by name
  *
  * @param string $renderName
  * @return BlockInterface|null
  */
 protected function getRenderInstance($renderName)
 {
     if (!isset($this->renderInstances[$renderName])) {
         $blockMeta = isset($this->config['renders'][$renderName]) ? $this->config['renders'][$renderName] : [];
         $class = isset($blockMeta['class']) ? $blockMeta['class'] : false;
         if ($class) {
             $element = isset($blockMeta['locator']) && isset($blockMeta['strategy']) ? $this->_rootElement->find($blockMeta['locator'], $blockMeta['strategy']) : $this->_rootElement;
             $config = ['renders' => isset($blockMeta['renders']) ? $blockMeta['renders'] : []];
             $block = $this->blockFactory->create($class, ['element' => $element, 'config' => $config]);
         } else {
             return null;
         }
         $this->renderInstances[$renderName] = $block;
     }
     return $this->renderInstances[$renderName];
 }
Esempio n. 2
0
 /**
  * Retrieve an instance of block
  *
  * @param string $blockName
  * @return BlockInterface
  * @throws \InvalidArgumentException
  */
 public function getBlockInstance($blockName)
 {
     if (!isset($this->blockInstances[$blockName])) {
         $blockMeta = isset($this->blocks[$blockName]) ? $this->blocks[$blockName] : [];
         $class = isset($blockMeta['class']) ? $blockMeta['class'] : false;
         if ($class) {
             $element = $this->_browser->find($blockMeta['locator'], $blockMeta['strategy']);
             $config = ['renders' => isset($blockMeta['renders']) ? $blockMeta['renders'] : []];
             $block = $this->_blockFactory->create($class, ['element' => $element, 'config' => $config]);
         } else {
             throw new \InvalidArgumentException(sprintf('There is no such block "%s" declared for the page "%s" ', $blockName, $class));
         }
         $this->blockInstances[$blockName] = $block;
     }
     // @todo fix to get link to new page if page reloaded
     return $this->blockInstances[$blockName]->reinitRootElement();
 }