protected function buildFieldOptions(FcField $fc_field) { $label = $fc_field->getLabel(); if (empty($label)) { $label = false; } return array('label' => $label, 'required' => false, 'constraints' => array(), 'attr' => array('data-type' => $fc_field->getType())); }
protected function makeValue(FcField $fc_field, &$data) { $value = $data[$fc_field->getName()]; if ($value instanceof UploadedFile) { return $this->uploadFile($value); } return $this->field_chain->getField($fc_field->getType())->verboseValue($value, $fc_field); }
protected function findRoots(FcField $fc_field, &$roots) { $fc_form = $fc_field->getFcForm(); if ($fc_form->isUsedAsWidget()) { foreach ($fc_form->getEntrances() as $entrance) { $this->findRoots($entrance, $roots); } } else { $roots[] = $fc_form; } }
protected function buildFormatOption(FcField $fc_field) { $params = $fc_field->getParams(); $format = array(); if (isset($params['date_format']) && !empty($params['date_format'])) { $format[] = $params['date_format']; } if (isset($params['time_format']) && !empty($params['time_format'])) { $format[] = $params['time_format']; } return implode(' ', $format); }
public function verboseValue($value, FcField $fc_field) { $verbose = array(); $params = $fc_field->getParams(); if (!is_array($value)) { $value = array($value); } foreach ($params['choices'] as $choice) { if (in_array($choice['value'], $value)) { $verbose[] = $choice['label']; } } return implode(', ', $verbose); }
protected function addField(FormBuilderInterface $builder, FcField $fc_field) { $field = $this->field_chain->getField($fc_field->getType()); $field->buildField($this->constraint_chain, $builder, $fc_field); }
/** * Creates and saves a field * * @param Request $request * @param $id * @param $type * @return JsonResponse * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException */ public function doCreateFieldAction(Request $request, $id, $type) { try { if (!$request->isXmlHttpRequest()) { throw $this->createAccessDeniedException(); } $fc_form = FcFormQuery::create()->findPk($id); if (!$fc_form instanceof FcForm) { throw $this->createNotFoundException(); } $field = new FcField(); $field->setType($type); $field->setFcForm($fc_form); $form_action = $this->admin->generateUrl('do_create_field', array('id' => $id, 'type' => $type)); $form = $this->getFieldFormType($field, $form_action); $form->handleRequest($request); if ($form->isValid()) { if (null !== $field->getInsertRank()) { $field->insertAtRank($field->getInsertRank()); } $field->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())))); }