コード例 #1
0
 /**
  * @Route("/dynamic-form/location", name="dynamic_form_location")
  * @Template()
  */
 public function locationFormAction(Request $request)
 {
     $country = $this->getCountry($request);
     $state = $this->getState($request);
     $city = $this->getCity($request);
     $locationData = new \PROCERGS\LoginCidadao\CoreBundle\Model\SelectData();
     if ($city instanceof City) {
         $locationData->setCity($city)->setState($city->getState())->setCountry($city->getState()->getCountry());
     } elseif ($state instanceof State) {
         $locationData->setCity(null)->setState($state)->setCountry($state->getCountry());
     } elseif ($country instanceof Country) {
         $locationData->setCity(null)->setState(null)->setCountry($country);
     }
     $level = $request->get('level');
     $data = new DynamicFormData();
     $data->setPlaceOfBirth($locationData);
     $formBuilder = $this->createFormBuilder($data, array('cascade_validation' => true));
     $this->addPlaceOfBirth($formBuilder, $level);
     return array('form' => $formBuilder->getForm()->createView());
 }