/** * Remove scheduled element * * @param ScheduledStructure $scheduledStructure * @param Structure $structure * @param string $elementName * @param bool $isChild * @return $this */ protected function removeElement(ScheduledStructure $scheduledStructure, Structure $structure, $elementName, $isChild = false) { $elementsToRemove = array_keys($structure->getChildren($elementName)); $scheduledStructure->unsetElement($elementName); foreach ($elementsToRemove as $element) { $this->removeElement($scheduledStructure, $structure, $element, true); } if (!$isChild) { $structure->unsetElement($elementName); } return $this; }
/** * @covers \Magento\Framework\View\Layout\ScheduledStructure::unsetElement */ public function testUnsetElement() { $this->assertTrue($this->_model->hasElement('element1')); $this->_model->unsetElement('element1'); $this->assertFalse($this->_model->hasElement('element1')); }
/** * 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; }