/** * @return FcForm */ public function getCustomWidget() { if ($this->custom_widget === false) { $this->custom_widget = FcFormQuery::create()->filterByAlias($this->getType())->filterByIsWidget(true)->findOne(); } return $this->custom_widget; }
protected function getFcForm() { if (is_null($this->fc_form)) { $form_id = $this->getRequest()->get('form_id'); $this->fc_form = FcFormQuery::create()->findPk((int) $form_id); if (!$this->fc_form instanceof FcForm) { $this->fc_form = new FcForm(); } } return $this->fc_form; }
protected function buildTypeChoices() { $inbuilt = array(); $custom = array(); foreach ($this->field_chain->getFields() as $alias => $field) { $inbuilt[$alias] = $field->getName(); } /** @var FcForm[] $fc_forms */ $fc_forms = FcFormQuery::create()->filterByIsWidget(true)->orderByTitle()->find(); foreach ($fc_forms as $fc_form) { if ($fc_form->getId() != $this->fc_form_id) { $custom[$fc_form->getAlias()] = $fc_form->getTitle(); } } if (!empty($custom)) { return array('fc.label.admin.field.widget.inbuilt' => $inbuilt, 'fc.label.admin.field.widget.custom' => $custom); } else { return $inbuilt; } }
public function doConfigureAction(Request $request, $form_id) { try { if (!$request->isXmlHttpRequest()) { throw $this->createNotFoundException(); } $fc_form = FcFormQuery::create()->findPk((int) $form_id); if (!$fc_form instanceof FcForm) { throw $this->createNotFoundException('Form not found'); } $form_action = $this->admin->generateUrl('do_configure', array('form_id' => $fc_form->getId())); $form = $this->createForm(new RequestCommonType($form_action, $fc_form), FcRequestSettingQuery::create()->filterByFcForm($fc_form)->findOneOrCreate()); $form->handleRequest($request); if ($form->isValid()) { /** @var FcRequestSetting $setting */ $setting = $form->getData(); $setting->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 guessFcForm(Request $request) { $method = strtoupper($request->getMethod()); $fc_forms = FcFormQuery::create()->filterByMethod($method)->find(); /** @var FcForm $fc_form */ foreach ($fc_forms as $fc_form) { $parameter_bag = $method == 'POST' ? $request->request : $request->query; if ($parameter_bag->has($fc_form->getAlias())) { return $fc_form; } } return null; }
/** * 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())))); }