Esempio n. 1
0
 /**
  * @covers \Magento\Framework\View\Layout\ScheduledStructure::setElement
  */
 public function testSetElement()
 {
     $data = ['some', 'new', 'data'];
     /** Test add new element */
     $this->assertFalse($this->_model->hasElement('new_element'));
     $this->_model->setElement('new_element', $data);
     $this->assertEquals($data, $this->_model->getElement('new_element'));
     /** Test override existing element */
     $this->assertTrue($this->_model->hasElement('element1'));
     $this->_model->setElement('element1', $data);
     $this->assertEquals($data, $this->_model->getElement('element1'));
 }
Esempio n. 2
0
 /**
  * Create block and set related data
  *
  * @param \Magento\Framework\View\Layout\ScheduledStructure $scheduledStructure
  * @param \Magento\Framework\View\Layout\Data\Structure $structure
  * @param string $elementName
  * @return \Magento\Framework\View\Element\AbstractBlock
  */
 protected function generateBlock(Layout\ScheduledStructure $scheduledStructure, Layout\Data\Structure $structure, $elementName)
 {
     list(, $data) = $scheduledStructure->getElement($elementName);
     $attributes = $data['attributes'];
     if (!empty($attributes['group'])) {
         $structure->addToParentGroup($elementName, $attributes['group']);
     }
     if (!empty($attributes['display'])) {
         $structure->setAttribute($elementName, 'display', $attributes['display']);
     }
     // create block
     $className = $attributes['class'];
     $block = $this->createBlock($className, $elementName, ['data' => $this->evaluateArguments($data['arguments'])]);
     if (!empty($attributes['template'])) {
         $block->setTemplate($attributes['template']);
     }
     if (!empty($attributes['ttl'])) {
         $ttl = (int) $attributes['ttl'];
         $block->setTtl($ttl);
     }
     return $block;
 }
Esempio n. 3
0
 /**
  * Creates block object based on xml node data and add it to the layout
  *
  * @param string $elementName
  * @return \Magento\Framework\View\Element\AbstractBlock|void
  * @throws \Magento\Framework\Exception
  */
 protected function _generateBlock($elementName)
 {
     list($type, $node, $actions, $args) = $this->_scheduledStructure->getElement($elementName);
     if ($type !== Element::TYPE_BLOCK) {
         throw new \Magento\Framework\Exception("Unexpected element type specified for generating block: {$type}.");
     }
     $configPath = (string) $node->getAttribute('ifconfig');
     if (!empty($configPath) && !$this->_scopeConfig->isSetFlag($configPath, $this->scopeType, $this->scopeResolver->getScope())) {
         $this->_scheduledStructure->unsetElement($elementName);
         return;
     }
     $group = (string) $node->getAttribute('group');
     if (!empty($group)) {
         $this->_structure->addToParentGroup($elementName, $group);
     }
     // create block
     $className = (string) $node['class'];
     $arguments = $this->_evaluateArguments($args);
     $block = $this->_createBlock($className, $elementName, array('data' => $arguments));
     if (!empty($node['template'])) {
         $templateFileName = (string) $node['template'];
         $block->setTemplate($templateFileName);
     }
     if (!empty($node['ttl'])) {
         $ttl = (int) $node['ttl'];
         $block->setTtl($ttl);
     }
     $this->_scheduledStructure->unsetElement($elementName);
     // execute block methods
     foreach ($actions as $action) {
         list($actionNode, $parent) = $action;
         $this->_generateAction($actionNode, $parent);
     }
     return $block;
 }