/** * @return void * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testReorderToSiblingException() { $this->_structure->createElement('one', []); $this->_structure->createElement('two', []); $this->_structure->createElement('three', []); $this->_structure->setAsChild('two', 'one'); $this->_structure->reorderToSibling('one', 'three', 'two', 1); }
/** * Reorder a child of a specified element * * If $offsetOrSibling is null, it will put the element to the end * If $offsetOrSibling is numeric (integer) value, it will put the element after/before specified position * Otherwise -- after/before specified sibling * * @param string $parentName * @param string $childName * @param string|int|null $offsetOrSibling * @param bool $after * @return void */ public function reorderChild($parentName, $childName, $offsetOrSibling, $after = true) { if (is_numeric($offsetOrSibling)) { $offset = (int) abs($offsetOrSibling) * ($after ? 1 : -1); $this->_structure->reorderChild($parentName, $childName, $offset); } elseif (null === $offsetOrSibling) { $this->_structure->reorderChild($parentName, $childName, null); } else { $children = $this->getChildNames($parentName); if ($this->_structure->getChildId($parentName, $offsetOrSibling) !== false) { $offsetOrSibling = $this->_structure->getChildId($parentName, $offsetOrSibling); } $sibling = $this->_filterSearchMinus($offsetOrSibling, $children, $after); if ($childName !== $sibling) { $siblingParentName = $this->_structure->getParentId($sibling); if ($parentName !== $siblingParentName) { $this->_logger->log("Broken reference: the '{$childName}' tries to reorder itself towards '{$sibling}', but " . "their parents are different: '{$parentName}' and '{$siblingParentName}' respectively.", \Zend_Log::CRIT); return; } $this->_structure->reorderToSibling($parentName, $childName, $sibling, $after ? 1 : -1); } } }