/** * Creates and saves an action * * @param Request $request * @param $id * @param $behavior_id * @param $check * @param $action * @return JsonResponse * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function doCreateBehaviorActionAction(Request $request, $id, $behavior_id, $check, $action) { try { if (!$request->isXmlHttpRequest()) { throw $this->createAccessDeniedException(); } $fc_form = FcFormQuery::create()->findPk($id); if (!$fc_form instanceof FcForm) { throw $this->createNotFoundException(); } $behavior = FcFormBehaviorQuery::create()->findPk((int) $behavior_id); if (!$behavior instanceof FcFormBehavior) { throw $this->createNotFoundException(); } $fc_action = new FcFormBehaviorAction(); $fc_action->setAction($action); $fc_action->setFcFormBehavior($behavior); $fc_action->setCheck($check); $form_action = $this->admin->generateUrl('do_create_behavior_action', array('id' => $id, 'action' => $action, 'behavior_id' => $behavior_id, 'check' => $check)); $form = $this->createForm(new BehaviorActionCommonType($form_action, $this->get('translator'), $this->container->get('fc.behavior.action.chain')->getParamsBuilder($action, $this->admin->getSubject())), $fc_action); $form->handleRequest($request); if ($form->isValid()) { $fc_action->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())))); }
public function getBehaviors() { if (is_null($this->behaviors)) { $this->behaviors = FcFormBehaviorQuery::create()->filterByFcForm($this)->filterByIsActive(true)->find(); } return $this->behaviors; }