protected function addField($name)
 {
     switch ($name) {
         case 'name':
         case 'path':
             $this->form->setDefault($name, $this->menu[$name]);
             $this->form->setValidator($name, new sfValidatorString(array('required' => true)));
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'label':
             $this->form->setDefault($name, $this->menu[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormInput());
             break;
         case 'parentId':
             // Get menuTree array with menu depths
             $menuTree = QubitMenu::getTreeById(QubitMenu::ROOT_ID);
             // Build an array of choices for "parentId" select box (with blank line)
             $choices = array(1 => '[ ' . $this->context->i18n->__('Top') . ' ]');
             foreach ($menuTree as $menu) {
                 $choices[$menu['id']] = str_repeat('-', $menu['depth']) . ' ' . $menu['name'];
             }
             if (null !== $this->menu->parentId) {
                 $this->form->setDefault('parentId', $this->menu->parentId);
             }
             $this->form->setValidator('parentId', new sfValidatorString(array('required' => true)));
             $this->form->setWidget('parentId', new sfWidgetFormSelect(array('choices' => $choices)));
             break;
         case 'description':
             $this->form->setDefault($name, $this->menu[$name]);
             $this->form->setValidator($name, new sfValidatorString());
             $this->form->setWidget($name, new sfWidgetFormTextarea());
             break;
     }
 }
 public function execute($request)
 {
     // Re-order menus if "move" parameter passed
     if (isset($request->move) && ($menu = QubitMenu::getById($request->move))) {
         if (isset($request->before)) {
             $menu->moveBeforeById($request->before);
         } else {
             if (isset($request->after)) {
                 $menu->moveAfterById($request->after);
             }
         }
         // Remove cache
         if ($this->context->getViewCacheManager() !== null) {
             $this->context->getViewCacheManager()->remove('@sf_cache_partial?module=menu&action=_browseMenu&sf_cache_key=*');
             $this->context->getViewCacheManager()->remove('@sf_cache_partial?module=menu&action=_mainMenu&sf_cache_key=*');
         }
     }
     // Get an array with menu ids and depth (relative to top menu) to create
     // and indented list
     $this->menuTree = QubitMenu::getTreeById(QubitMenu::ROOT_ID);
     foreach ($this->menuTree as $i => $menu) {
         // Build an array of siblings for each parentId for figuring out
         // prev/next buttons
         $siblingList[$menu['parentId']][] = array('id' => $menu['id'], 'pos' => $i);
     }
     // Build prev/next values based on number of siblings
     foreach ($siblingList as $siblings) {
         foreach ($siblings as $i => $sibling) {
             if (0 < $i) {
                 $this->menuTree[$sibling['pos']]['prev'] = $siblings[$i - 1]['id'];
             }
             if (count($siblings) - 1 > $i) {
                 $this->menuTree[$sibling['pos']]['next'] = $siblings[$i + 1]['id'];
             }
         }
     }
 }