Example #1
0
 private function addNameControl()
 {
     $nameControl = $this->addText('name', 'Name');
     $nameControl->setRequired();
     if ($this->editedCategory !== null) {
         $nameControl->setDefaultValue($this->editedCategory->getName());
     }
 }
Example #2
0
 private function updateCategory(CategoriesForm $form)
 {
     $values = $form->getValues();
     $this->category->setName($values->name);
     if ($values->parentCategory === CategoriesForm::ROOT_CATEGORY_KEY) {
         $parentCategory = null;
     } else {
         $parentCategory = $this->categoryService->getById($values->parentCategory);
     }
     $this->category->setParent($parentCategory);
     try {
         if (!$form->hasErrors()) {
             $this->categoryService->update($this->category);
             $this->flashMessage(sprintf('Category %s has been updated.', $this->category->getName()));
             $this->redirect(':Admin:Category:List:');
         }
     } catch (EntityDuplicateException $e) {
         $form->addError(sprintf('Category with name %s already exists.', $this->category->getName()));
     }
 }