mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 02:23:51 +00:00
add validation to single task controller::new
This commit is contained in:
@@ -13,6 +13,7 @@ use Chill\TaskBundle\Form\SingleTaskType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
||||
use Symfony\Component\Form\FormFactoryInterface;
|
||||
use Chill\TaskBundle\Security\Authorization\TaskVoter;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
|
||||
class SingleTaskController extends Controller
|
||||
{
|
||||
@@ -58,6 +59,7 @@ class SingleTaskController extends Controller
|
||||
$task = (new SingleTask())
|
||||
->setPerson($person)
|
||||
->setAssignee($this->getUser())
|
||||
->setType('task_default')
|
||||
;
|
||||
|
||||
$this->denyAccessUnlessGranted(TaskVoter::CREATE, $task, 'You are not '
|
||||
@@ -67,13 +69,17 @@ class SingleTaskController extends Controller
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($task);
|
||||
|
||||
$this->addFlash('success', "The task is created");
|
||||
|
||||
$em->flush();
|
||||
if ($form->isSubmitted()) {
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($task);
|
||||
|
||||
$this->addFlash('success', "The task is created");
|
||||
|
||||
$em->flush();
|
||||
} else {
|
||||
$this->addFlash('error', "This form contains errors");
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render('ChillTaskBundle:SingleTask:new.html.twig', array(
|
||||
@@ -90,7 +96,8 @@ class SingleTaskController extends Controller
|
||||
protected function createCreateForm(SingleTask $task)
|
||||
{
|
||||
$form = $this->createForm(SingleTaskType::class, $task, [
|
||||
'center' => $task->getCenter()
|
||||
'center' => $task->getCenter(),
|
||||
'role' => new Role(TaskVoter::CREATE)
|
||||
]);
|
||||
|
||||
$form->add('submit', SubmitType::class);
|
||||
|
Reference in New Issue
Block a user