/** * @covers \Magento\Framework\View\Layout\ScheduledStructure::unsetStructureElement */ public function testUnsetStructureElement() { $this->assertTrue($this->_model->hasStructureElement('element1')); $this->_model->unsetStructureElement('element1'); $this->assertFalse($this->_model->hasStructureElement('element1')); }
/** * Process queue of structural elements and actually add them to structure, and schedule elements for generation * * The catch is to populate parents first, if they are not in the structure yet. * Since layout updates could come in arbitrary order, a case is possible where an element is declared in reference, * while referenced element itself is not declared yet. * * @param \Magento\Framework\View\Layout\ScheduledStructure $scheduledStructure * @param Layout\Data\Structure $structure * @param string $key in _scheduledStructure represent element name * @return void * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function scheduleElement(Layout\ScheduledStructure $scheduledStructure, Layout\Data\Structure $structure, $key) { $row = $scheduledStructure->getStructureElement($key); $data = $scheduledStructure->getStructureElementData($key); // if we have reference container to not existed element if (!isset($row[self::SCHEDULED_STRUCTURE_INDEX_TYPE])) { $this->logger->critical("Broken reference: missing declaration of the element '{$key}'."); $scheduledStructure->unsetPathElement($key); $scheduledStructure->unsetStructureElement($key); return; } list($type, $alias, $parentName, $siblingName, $isAfter) = $row; $name = $this->_createStructuralElement($structure, $key, $type, $parentName . $alias); if ($parentName) { // recursively populate parent first if ($scheduledStructure->hasStructureElement($parentName)) { $this->scheduleElement($scheduledStructure, $structure, $parentName); } if ($structure->hasElement($parentName)) { try { $structure->setAsChild($name, $parentName, $alias); } catch (\Exception $e) { $this->logger->critical($e); } } else { $scheduledStructure->setElementToBrokenParentList($key); $this->logger->critical("Broken reference: the '{$name}' element cannot be added as child to '{$parentName}', " . 'because the latter doesn\'t exist'); } } // Move from scheduledStructure to scheduledElement $scheduledStructure->unsetStructureElement($key); $scheduledStructure->setElement($name, [$type, $data]); /** * Some elements provide info "after" or "before" which sibling they are supposed to go * Make sure to populate these siblings as well and order them correctly */ if ($siblingName) { if ($scheduledStructure->hasStructureElement($siblingName)) { $this->scheduleElement($scheduledStructure, $structure, $siblingName); } $structure->reorderChildElement($parentName, $name, $siblingName, $isAfter); } }
/** * Process queue of structural elements and actually add them to structure, and schedule elements for generation * * The catch is to populate parents first, if they are not in the structure yet. * Since layout updates could come in arbitrary order, a case is possible where an element is declared in reference, * while referenced element itself is not declared yet. * * @param string $key in _scheduledStructure represent element name * @return void * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ protected function _scheduleElement($key) { $row = $this->_scheduledStructure->getStructureElement($key); if (!isset($row[self::SCHEDULED_STRUCTURE_INDEX_LAYOUT_ELEMENT])) { $this->_logger->log("Broken reference: missing declaration of the element '{$key}'.", \Zend_Log::CRIT); $this->_scheduledStructure->unsetPathElement($key); $this->_scheduledStructure->unsetStructureElement($key); return; } list($type, $alias, $parentName, $siblingName, $isAfter, $node) = $row; $name = $this->_createStructuralElement($key, $type, $parentName . $alias); if ($parentName) { // recursively populate parent first if ($this->_scheduledStructure->hasStructureElement($parentName)) { $this->_scheduleElement($parentName, $this->_scheduledStructure->getStructureElement($parentName)); } if ($this->_structure->hasElement($parentName)) { try { $this->_structure->setAsChild($name, $parentName, $alias); } catch (\Exception $e) { $this->_logger->log($e->getMessage()); } } else { $this->_logger->log("Broken reference: the '{$name}' element cannot be added as child to '{$parentName}', " . 'because the latter doesn\'t exist', \Zend_Log::CRIT); } } $this->_scheduledStructure->unsetStructureElement($key); $data = array($type, $node, isset($row['actions']) ? $row['actions'] : array(), isset($row['arguments']) ? $row['arguments'] : array(), isset($row['attributes']) ? $row['attributes'] : array()); $this->_scheduledStructure->setElement($name, $data); /** * Some elements provide info "after" or "before" which sibling they are supposed to go * Make sure to populate these siblings as well and order them correctly */ if ($siblingName) { if ($this->_scheduledStructure->hasStructureElement($siblingName)) { $this->_scheduleElement($siblingName); } $this->reorderChild($parentName, $name, $siblingName, $isAfter); } }