/**
  * Add a block
  *
  * @param string $name
  * @param string $class
  * @param array $arguments [optional]
  * @return BlockPool
  * @throws \InvalidArgumentException
  */
 public function add($name, $class, array $arguments = [])
 {
     if (!class_exists($class)) {
         throw new \InvalidArgumentException((string) new \Magento\Framework\Phrase('Invalid Block class name: %1', [$class]));
     }
     $block = $this->blockFactory->createBlock($class, $arguments);
     $this->blocks[$name] = $block;
     return $this;
 }
Exemple #2
0
 /**
  * Add a block
  *
  * @param string $name
  * @param string $class
  * @param array $arguments [optional]
  * @return BlockPool
  * @throws \InvalidArgumentException
  */
 public function add($name, $class, array $arguments = array())
 {
     if (!class_exists($class)) {
         throw new \InvalidArgumentException(__('Invalid Block class name: ' . $class));
     }
     $block = $this->blockFactory->createBlock($class, $arguments);
     $this->blocks[$name] = $block;
     return $this;
 }
 /**
  * Add data source
  *
  * @param string $name
  * @param string $class
  * @return object
  * @throws \Exception
  */
 public function add($name, $class)
 {
     if (!isset($this->dataSources[$name])) {
         if (!class_exists($class)) {
             throw new \Exception(__('Invalid Data Source class name: ' . $class));
         }
         $data = $this->blockFactory->createBlock($class);
         $this->dataSources[$name] = $data;
     }
     return $this->dataSources[$name];
 }
 /**
  * Add data source
  *
  * @param string $name
  * @param string $class
  * @return object
  * @throws \Exception
  */
 public function add($name, $class)
 {
     if (!isset($this->dataSources[$name])) {
         if (!class_exists($class)) {
             throw new \InvalidArgumentException((string) new \Magento\Framework\Phrase('Invalid Data Source class name: %1', [$class]));
         }
         $data = $this->blockFactory->createBlock($class);
         $this->dataSources[$name] = $data;
     }
     return $this->dataSources[$name];
 }
 /**
  * @param string $renderer
  * @return \Magento\Framework\View\Element\BlockInterface
  */
 public function getRenderer($renderer)
 {
     if (is_string($renderer) && $renderer) {
         return $this->_blockFactory->createBlock($renderer, []);
     } else {
         return $renderer;
     }
 }
Exemple #6
0
 /**
  * Retrieve tooltip text
  *
  * @return string
  */
 public function getTooltip()
 {
     if (isset($this->_data['tooltip'])) {
         return $this->_getTranslatedAttribute('tooltip');
     } elseif (isset($this->_data['tooltip_block'])) {
         return $this->_blockFactory->createBlock($this->_data['tooltip_block'])->toHtml();
     }
     return '';
 }
Exemple #7
0
 /**
  * Element output getter
  *
  * @return string
  */
 public function getElementHtml()
 {
     $product = $this->_coreRegistry->registry('current_product');
     /** @var $formBlock \Magento\RecurringPayment\Block\Adminhtml\Payment\Edit\Form */
     $formBlock = $this->_blockFactory->createBlock('Magento\\RecurringPayment\\Block\\Adminhtml\\Payment\\Edit\\Form');
     $formBlock->setNameInLayout('adminhtml_recurring_payment_edit_form');
     $formBlock->setParentElement($this->_element);
     $formBlock->setProductEntity($product);
     $output = $formBlock->toHtml();
     // make the payment element dependent on is_recurring
     /** @var $dependencies \Magento\Backend\Block\Widget\Form\Element\Dependence */
     $dependencies = $this->_blockFactory->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Element\\Dependence');
     $dependencies->setNameInLayout('adminhtml_recurring_payment_edit_form_dependence');
     $dependencies->addFieldMap('is_recurring', 'product[is_recurring]');
     $dependencies->addFieldMap($this->_element->getHtmlId(), $this->_element->getName());
     $dependencies->addFieldDependence($this->_element->getName(), 'product[is_recurring]', '1');
     $dependencies->addConfigOptions(array('levels_up' => 2));
     $output .= $dependencies->toHtml();
     return $output;
 }
Exemple #8
0
 /**
  * Create block object instance based on block type
  *
  * @param string|\Magento\Framework\View\Element\AbstractBlock $block
  * @param array $arguments
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function getBlockInstance($block, array $arguments = [])
 {
     if ($block && is_string($block)) {
         try {
             $block = $this->blockFactory->createBlock($block, $arguments);
         } catch (\ReflectionException $e) {
             $this->logger->critical($e->getMessage());
         }
     }
     if (!$block instanceof \Magento\Framework\View\Element\AbstractBlock) {
         throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase('Invalid block type: %1', [$block]));
     }
     return $block;
 }
Exemple #9
0
 /**
  * Get block singleton
  *
  * @param string $type
  * @return \Magento\Framework\App\Helper\AbstractHelper
  * @throws \Magento\Framework\Model\Exception
  */
 public function getBlockSingleton($type)
 {
     if (!isset($this->_helpers[$type])) {
         if (!$type) {
             throw new \Magento\Framework\Model\Exception('Invalid block type');
         }
         $helper = $this->_blockFactory->createBlock($type);
         if ($helper) {
             if ($helper instanceof \Magento\Framework\View\Element\AbstractBlock) {
                 $helper->setLayout($this);
             }
             $this->_helpers[$type] = $helper;
         }
     }
     return $this->_helpers[$type];
 }
 /**
  * @expectedException \LogicException
  */
 public function testCreateBlockWithException()
 {
     $this->blockFactory->createBlock('invalid_class_name');
 }