/** * 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. * * @SuppressWarnings(PHPMD.NPathComplexity) * @param string $key in _scheduledStructure represent element name */ protected function _scheduleElement($key) { $row = $this->_scheduledStructure->getStructureElement($key); if (!isset($row[self::SCHEDULED_STRUCTURE_INDEX_LAYOUT_ELEMENT])) { Mage::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)) { $this->_structure->setAsChild($name, $parentName, $alias); } else { Mage::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()); $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); } }
/** * @covers Mage_Core_Model_Layout_ScheduledStructure::unsetPathElement */ public function testUnsetPathElement() { $this->assertTrue($this->_model->hasPath('path1')); $this->_model->unsetPathElement('path1'); $this->assertFalse($this->_model->hasPath('path1')); }