/** * Creates and saves a listener * * @param Request $request * @param $id * @param $listener * @return JsonResponse * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function doCreateListenerAction(Request $request, $id, $listener) { try { if (!$request->isXmlHttpRequest()) { throw $this->createAccessDeniedException(); } $fc_form = FcFormQuery::create()->findPk($id); if (!$fc_form instanceof FcForm) { throw $this->createNotFoundException(); } $fc_listener = new FcFormEventListener(); $fc_listener->setListener($listener); $fc_listener->setFcForm($fc_form); $form_action = $this->admin->generateUrl('do_create_listener', array('id' => $id, 'listener' => $listener)); $form = $this->createForm(new ListenerCommonType($form_action, $this->get('translator'), $this->container->get('fc.listener.chain')->getParamsBuilder($listener, $this->admin->getSubject())), $fc_listener); $form->handleRequest($request); if ($form->isValid()) { $fc_listener->save(); return new JsonResponse(array('success' => true)); } } catch (\Exception $e) { return new JsonResponse(array('success' => false, 'view' => 'Error ' . $e->getCode() . ': ' . $e->getMessage())); } return new JsonResponse(array('success' => false, 'view' => $this->renderView('FenrizbesFormConstructorBundle:SonataAdmin/FcForm:form.html.twig', array('form' => $form->createView())))); }