mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 22:04:23 +00:00
controller: merge newAction and createAction
This commit is contained in:
parent
c7ee9b8ebb
commit
4578625bb2
@ -86,33 +86,6 @@ class EventController extends Controller
|
||||
'q' => '@event'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Event entity.
|
||||
*
|
||||
*/
|
||||
public function createAction(Request $request)
|
||||
{
|
||||
$entity = new Event();
|
||||
$form = $this->createCreateForm($entity);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans('The event was created'));
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event__event_show', array('event_id' => $entity->getId())));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Event:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
'form' => $form->createView(),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a form to create a Event entity.
|
||||
@ -124,7 +97,6 @@ class EventController extends Controller
|
||||
private function createCreateForm(Event $entity)
|
||||
{
|
||||
$form = $this->createForm(EventType::class, $entity, array(
|
||||
'action' => $this->generateUrl('chill_event__event_create'),
|
||||
'method' => 'POST',
|
||||
'center' => $entity->getCenter(),
|
||||
'role' => new Role('CHILL_EVENT_CREATE')
|
||||
@ -192,6 +164,18 @@ class EventController extends Controller
|
||||
$entity->setCenter($center);
|
||||
|
||||
$form = $this->createCreateForm($entity);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isValid()) {
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$em->persist($entity);
|
||||
$em->flush();
|
||||
|
||||
$this->addFlash('success', $this->get('translator')
|
||||
->trans('The event was created'));
|
||||
|
||||
return $this->redirect($this->generateUrl('chill_event__event_show', array('event_id' => $entity->getId())));
|
||||
}
|
||||
|
||||
return $this->render('ChillEventBundle:Event:new.html.twig', array(
|
||||
'entity' => $entity,
|
||||
|
@ -25,11 +25,7 @@ chill_event__event_new_pickcenter:
|
||||
chill_event__event_new:
|
||||
path: /new
|
||||
defaults: { _controller: "ChillEventBundle:Event:new" }
|
||||
|
||||
chill_event__event_create:
|
||||
path: /create
|
||||
defaults: { _controller: "ChillEventBundle:Event:create" }
|
||||
methods: POST
|
||||
methods: [ GET, POST ]
|
||||
|
||||
chill_event__event_edit:
|
||||
path: /{event_id}/edit
|
||||
|
Loading…
x
Reference in New Issue
Block a user