/** * 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')); }