Adding CustomFieldsData for Report

This commit is contained in:
Marc Ducobu 2014-11-08 18:34:19 +01:00
parent c0c36bc1ec
commit 0fe3962968
2 changed files with 11 additions and 7 deletions

View File

@ -95,12 +95,13 @@ class ReportController extends Controller
* *
* @return \Symfony\Component\Form\Form The form * @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( $form = $this->createForm(new ReportType(), $entity, array(
'action' => $this->generateUrl('report_create'), 'action' => $this->generateUrl('report_create'),
'method' => 'POST', 'method' => 'POST',
'em' => $this->getDoctrine()->getManager(), 'em' => $this->getDoctrine()->getManager(),
'cFGroup' => $cFGroup,
)); ));
$form->add('submit', 'submit', array('label' => 'Create')); $form->add('submit', 'submit', array('label' => 'Create'));
@ -120,13 +121,14 @@ class ReportController extends Controller
$cFGroupId = $request->query->get('cFGroup'); $cFGroupId = $request->query->get('cFGroup');
if($cFGroupId) { if(! $cFGroupId) {
$entity->setCFGroup( throw new Exception("Error Processing Request", 1);
$em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')->find($cFGroupId)
);
} }
$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( return $this->render('ChillReportBundle:Report:new.html.twig', array(
'entity' => $entity, 'entity' => $entity,

View File

@ -24,7 +24,7 @@ class ReportType extends AbstractType
->add('person') ->add('person')
->add('date') ->add('date')
->add('scope') ->add('scope')
->add('cFData') ->add('cFData', 'custom_field', array('group' => $options['cFGroup']))
->add( ->add(
$builder->create('cFGroup', 'text') $builder->create('cFGroup', 'text')
->addModelTransformer($transformer) ->addModelTransformer($transformer)
@ -43,10 +43,12 @@ class ReportType extends AbstractType
$resolver->setRequired(array( $resolver->setRequired(array(
'em', 'em',
'cFGroup',
)); ));
$resolver->setAllowedTypes(array( $resolver->setAllowedTypes(array(
'em' => 'Doctrine\Common\Persistence\ObjectManager', 'em' => 'Doctrine\Common\Persistence\ObjectManager',
'cFGroup' => 'Chill\CustomFieldsBundle\Entity\CustomFieldsGroup'
)); ));
} }