コード例 #1
0
 /**
  * Edit a navigation item
  */
 public function editAction()
 {
     $itemName = $this->params->getRequired('name');
     $itemType = $this->params->getRequired('type');
     $referrer = $this->params->get('referrer', 'index');
     $user = $this->Auth()->getUser();
     if ($user->can('config/application/navigation')) {
         $itemOwner = $this->params->get('owner', $user->getUsername());
     } else {
         $itemOwner = $user->getUsername();
     }
     $form = new NavigationConfigForm();
     $form->setUser($user);
     $form->setShareConfig(Config::navigation($itemType));
     $form->setUserConfig(Config::navigation($itemType, $itemOwner));
     $form->setRedirectUrl($referrer === 'shared' ? 'navigation/shared' : 'navigation');
     $form->setOnSuccess(function (NavigationConfigForm $form) use($itemName) {
         $data = $form::transformEmptyValuesToNull($form->getValues());
         try {
             $form->edit($itemName, $data);
         } catch (NotFoundError $e) {
             throw $e;
         } 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(sprintf(t('Navigation item "%s" successfully updated'), $itemName));
             return true;
         }
         return false;
     });
     try {
         $form->load($itemName);
         $form->handleRequest();
     } catch (NotFoundError $_) {
         $this->httpNotFound(sprintf($this->translate('Navigation item "%s" not found'), $itemName));
     }
     $this->renderForm($form, $this->translate('Update Navigation Item'));
 }
コード例 #2
0
 /**
  * Edit a navigation item
  */
 public function editAction()
 {
     $itemName = $this->params->getRequired('name');
     $referrer = $this->params->get('referrer', 'index');
     $form = new NavigationConfigForm();
     $form->setRedirectUrl($referrer === 'shared' ? 'navigation/shared' : 'navigation');
     $form->setItemTypes($this->listItemTypes());
     $form->setTitle(sprintf($this->translate('Edit Navigation Item %s'), $itemName));
     $form->setUser($this->Auth()->getUser());
     $form->setShareConfig(Config::app('navigation'));
     $form->setOnSuccess(function (NavigationConfigForm $form) use($itemName) {
         $data = array_map(function ($v) {
             return $v !== '' ? $v : null;
         }, $form->getValues());
         try {
             $form->edit($itemName, $data);
         } catch (NotFoundError $e) {
             throw $e;
         } 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(sprintf(t('Navigation item "%s" successfully updated'), $itemName));
             return true;
         }
         return false;
     });
     try {
         $form->load($itemName);
         $form->handleRequest();
     } catch (NotFoundError $_) {
         $this->httpNotFound(sprintf($this->translate('Navigation item "%s" not found'), $itemName));
     }
     $this->view->form = $form;
     $this->render('form');
 }