/** * @Request({"id": "int", "item": "array", "menu": "int"}, csrf=true) */ public function saveAction($id, $data, $menuId = null) { try { if (!($item = $this->items->find($id))) { if (!($menu = $this->menus->find($menuId))) { throw new Exception(__('Invalid menu.')); } $item = new Item(); $item->setMenu($menu); $item->setMenuId($menu->getId()); } if (!$data['url']) { $data['url'] = $data['link']; } $this->items->save($item, $data); $id = $item->getId(); $this['message']->success($id ? __('Menu item saved.') : __('Menu item created.')); } catch (Exception $e) { $this['message']->error($e->getMessage()); } catch (InvalidParameterException $e) { $this['message']->error(__('Invalid url.')); } return $id ? $this->redirect('@system/item/edit', compact('id')) : $this->redirect('@system/item/add', ['menu' => $menuId]); }