/** * Build menu model from config * * @return Mage_Backend_Model_Menu * @throws InvalidArgumentException|BadMethodCallException|OutOfRangeException|Exception */ public function getMenu() { try { $this->_initMenu(); return $this->_menu; } catch (InvalidArgumentException $e) { $this->_logger->logException($e); throw $e; } catch (BadMethodCallException $e) { $this->_logger->logException($e); throw $e; } catch (OutOfRangeException $e) { $this->_logger->logException($e); throw $e; } catch (Exception $e) { throw $e; } }
public function testReorderReordersItemOnItsLevel() { $this->_logger->expects($this->any())->method('log'); $subMenu = new Mage_Backend_Model_Menu(array('logger' => $this->_logger)); $this->_items['item1']->expects($this->any())->method("hasChildren")->will($this->returnValue(true)); $this->_items['item1']->expects($this->any())->method("getChildren")->will($this->returnValue($subMenu)); $this->_model->add($this->_items['item1']); $this->_model->add($this->_items['item2'], 'item1', 10); $this->_model->add($this->_items['item3'], 'item1', 20); $this->_model->reorder('item2', 25); $subMenu->reorder('item3', 30); $this->assertEquals($this->_items['item2'], $subMenu[25]); $this->assertEquals($this->_items['item3'], $subMenu[30]); }
/** * Remove menu item by id * * @param string $itemId * @return bool */ public function remove($itemId) { $result = false; foreach ($this as $key => $item) { /** @var $item Mage_Backend_Model_Menu_Item */ if ($item->getId() == $itemId) { unset($this[$key]); $result = true; $this->_logger->log(sprintf('Remove on item with id %s was processed', $item->getId())); break; } if ($item->hasChildren() && ($result = $item->getChildren()->remove($itemId))) { break; } } return $result; }
/** * Get command object * @param array $data command params * @return Mage_Backend_Model_Menu_Builder_CommandAbstract */ protected function _getCommand($data) { switch ($data['type']) { case 'update': $command = $this->_factory->getModelInstance('Mage_Backend_Model_Menu_Builder_Command_Update', $data); $this->_logger->log(sprintf('Update on item with id %s was processed', $command->getId())); break; case 'remove': $command = $this->_factory->getModelInstance('Mage_Backend_Model_Menu_Builder_Command_Remove', $data); $this->_logger->log(sprintf('Remove on item with id %s was processed', $command->getId())); break; default: $command = $this->_factory->getModelInstance('Mage_Backend_Model_Menu_Builder_Command_Add', $data); break; } return $command; }