/** * Add a navigation item */ public function addAction() { $form = new NavigationConfigForm(); $form->setRedirectUrl('navigation'); $form->setUser($this->Auth()->getUser()); $form->setItemTypes($this->listItemTypes()); $form->addDescription($this->translate('Create a new navigation item, such as a menu entry or dashlet.')); // TODO: Fetch all "safe" parameters from the url and populate them $form->setDefaultUrl(rawurldecode($this->params->get('url', ''))); $form->setOnSuccess(function (NavigationConfigForm $form) { $data = $form::transformEmptyValuesToNull($form->getValues()); try { $form->add($data); } catch (Exception $e) { $form->error($e->getMessage()); return false; } if ($form->save()) { if ($data['type'] === 'menu-item') { $form->getResponse()->setRerenderLayout(); } Notification::success(t('Navigation item successfully created')); return true; } return false; }); $form->handleRequest(); $this->renderForm($form, $this->translate('New Navigation Item')); }
/** * Add a navigation item */ public function addAction() { $form = new NavigationConfigForm(); $form->setRedirectUrl('navigation'); $form->setItemTypes($this->listItemTypes()); $form->setTitle($this->translate('Create New Navigation Item')); $form->addDescription($this->translate('Create a new navigation item, such as a menu entry or dashlet.')); $form->setUser($this->Auth()->getUser()); $form->setShareConfig(Config::app('navigation')); $form->setOnSuccess(function (NavigationConfigForm $form) { $data = array_filter($form->getValues()); try { $form->add($data); } catch (Exception $e) { $form->error($e->getMessage()); return false; } if ($form->save()) { if (isset($data['type']) && $data['type'] === 'menu-item') { $form->getResponse()->setRerenderLayout(); } Notification::success(t('Navigation item successfully created')); return true; } return false; }); $form->handleRequest(); $this->view->form = $form; $this->render('form'); }