removeItem() public method

Delete menu item
public removeItem ( MenuItem $item ) : boolean | null
$item Xpressengine\Menu\Models\MenuItem item instance
return boolean | null
Example #1
0
 public function testRemoveItemThrowsExceptionWhenHasItem()
 {
     list($repo, $configs, $modules, $routes) = $this->getMocks();
     $instance = new MenuHandler($repo, $configs, $modules, $routes);
     $mockMenuItem = m::mock('Xpressengine\\Menu\\Models\\MenuItem');
     $mockMenuItem->shouldReceive('getDescendantCount')->andReturn(1);
     try {
         $instance->removeItem($mockMenuItem);
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $this->assertInstanceOf('Xpressengine\\Menu\\Exceptions\\CanNotDeleteMenuItemHaveChildException', $e);
     }
 }
Example #2
0
 /**
  * destroyItem
  * 메뉴 아이템 삭제 처리 메소드
  *
  * @param MenuHandler     $handler menu handler
  * @param string          $menuId  menu id
  * @param string          $itemId  item id
  *
  * @return RedirectResponse
  * @throws Exception
  */
 public function destroyItem(MenuHandler $handler, $menuId, $itemId)
 {
     $item = $handler->getItem($itemId);
     $menu = $item->menu;
     if ($menu->getKey() !== $menuId) {
         throw new InvalidArgumentHttpException(400);
     }
     XeDB::beginTransaction();
     try {
         $handler->removeItem($item);
         foreach (File::getByFileable($item->getKey()) as $file) {
             XeStorage::unBind($item->getKey(), $file);
         }
         $handler->deleteMenuItemTheme($item);
         $this->permissionUnregister($handler->permKeyString($item));
     } catch (Exception $e) {
         XeDB::rollback();
         return Redirect::back()->with('alert', ['type' => 'danger', 'message' => $e->getMessage()]);
     }
     XeDB::commit();
     return Redirect::route('settings.menu.index')->with('alert', ['type' => 'success', 'message' => 'MenuItem deleted']);
 }