From 0fe396296892e2ca78e31e9aae8a32322ca5864b Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Sat, 8 Nov 2014 18:34:19 +0100 Subject: [PATCH] Adding CustomFieldsData for Report --- Controller/ReportController.php | 14 ++++++++------ Form/ReportType.php | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Controller/ReportController.php b/Controller/ReportController.php index 3a5df68cb..7cd0288df 100644 --- a/Controller/ReportController.php +++ b/Controller/ReportController.php @@ -95,12 +95,13 @@ class ReportController extends Controller * * @return \Symfony\Component\Form\Form The form */ - private function createCreateForm(Report $entity) + private function createCreateForm(Report $entity, $cFGroup) { $form = $this->createForm(new ReportType(), $entity, array( 'action' => $this->generateUrl('report_create'), 'method' => 'POST', 'em' => $this->getDoctrine()->getManager(), + 'cFGroup' => $cFGroup, )); $form->add('submit', 'submit', array('label' => 'Create')); @@ -120,13 +121,14 @@ class ReportController extends Controller $cFGroupId = $request->query->get('cFGroup'); - if($cFGroupId) { - $entity->setCFGroup( - $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cFGroupId) - ); + if(! $cFGroupId) { + throw new Exception("Error Processing Request", 1); } - $form = $this->createCreateForm($entity); + $cFGroup = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cFGroupId); + $entity->setCFGroup($cFGroup); + + $form = $this->createCreateForm($entity, $cFGroup); return $this->render('ChillReportBundle:Report:new.html.twig', array( 'entity' => $entity, diff --git a/Form/ReportType.php b/Form/ReportType.php index 065bac978..2c6e2499e 100644 --- a/Form/ReportType.php +++ b/Form/ReportType.php @@ -24,7 +24,7 @@ class ReportType extends AbstractType ->add('person') ->add('date') ->add('scope') - ->add('cFData') + ->add('cFData', 'custom_field', array('group' => $options['cFGroup'])) ->add( $builder->create('cFGroup', 'text') ->addModelTransformer($transformer) @@ -43,10 +43,12 @@ class ReportType extends AbstractType $resolver->setRequired(array( 'em', + 'cFGroup', )); $resolver->setAllowedTypes(array( 'em' => 'Doctrine\Common\Persistence\ObjectManager', + 'cFGroup' => 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup' )); }