Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function onBindNormData(DataEvent $event)
 {
     $data = $event->getData();
     if (true === empty($data)) {
         return;
     }
     if (strpos($data, 'delete_') === false) {
         $upload = $this->em->getRepository('LowbiSystemBundle:Upload')->findOneById($data);
         if (!$upload) {
             throw $this->createNotFoundException($translator->trans('entities.notfound'));
         }
         $attributes = $event->getForm()->getTypes();
         $lastType = $attributes[count($attributes) - 1];
         $formType = get_class($lastType);
         if ($formType != null) {
             $type = substr($formType, strrpos($formType, '\\') + 1);
             $upload->setType($type);
         }
         $event->setData($upload);
     } else {
         $id = str_replace('delete_', '', $data);
         $upload = $this->em->getRepository('LowbiSystemBundle:Upload')->findOneById($id);
         $event->setData($upload);
     }
     return;
 }
 /**
  * Form event - removes image if scheduled.
  * 
  * @param DataEvent $event
  */
 public function bind(DataEvent $event)
 {
     $entity = $event->getData();
     if ($entity instanceof ImageInterface && null === $entity->getId() && null === $entity->getName()) {
         $event->setData(null);
     }
 }
 public function preBind(DataEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     if (null === $data || '' === $data) {
         $data = array();
     }
     if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
         throw new UnexpectedTypeException($data, 'array or (\\Traversable and \\ArrayAccess)');
     }
     // Remove all empty rows
     if ($this->allowDelete) {
         foreach ($form as $name => $child) {
             if (!isset($data[$name])) {
                 $form->remove($name);
             }
         }
     }
     // Add all additional rows
     if ($this->allowAdd) {
         foreach ($data as $name => $value) {
             if (!$form->has($name)) {
                 $form->add($this->factory->createNamed($this->type, $name, null, array_replace(array('property_path' => '[' . $name . ']'), $this->options)));
             }
         }
     }
 }
 public function preBind(DataEvent $event)
 {
     if (!$this->resizeOnBind) {
         return;
     }
     $form = $event->getForm();
     $data = $event->getData();
     if (null === $data || '' === $data) {
         $data = array();
     }
     if (!is_array($data) && !$data instanceof \Traversable) {
         throw new UnexpectedTypeException($data, 'array or \\Traversable');
     }
     // Remove all empty rows except for the prototype row
     foreach ($form as $name => $child) {
         $form->remove($name);
     }
     // Add all additional rows
     foreach ($data as $name => $value) {
         if (!$form->has($name)) {
             $options = array_merge($this->typeOptions, array('property_path' => '[' . $name . ']'));
             $form->add($this->factory->createNamed($this->type, $name, null, $options));
         }
         if (isset($value['_delete'])) {
             $this->removed[] = $name;
         }
     }
 }
 public function preSetData(DataEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     // During form creation setData() is called with null as an argument
     // by the FormBuilder constructor. You're only concerned with when
     // setData is called with an actual Entity object in it (whether new
     // or fetched with Doctrine). This if statement lets you skip right
     // over the null condition.
     if (null === $data) {
         return;
     }
     // Defaults
     $defaults = array();
     $classTypes = $this->em->createQuery('SELECT u from TSK\\ClassBundle\\Entity\\ClassType u WHERE u.organization=:org')->setParameter('org', $this->org_id)->getResult();
     if (count($classTypes)) {
         foreach ($classTypes as $classType) {
             $ctc = new ClassTypeCredit();
             $ctc->setClassType($classType);
             $ctc->setClass($data);
             $ctc->setValue(0);
             $defaults[$classType->getName()] = $ctc;
         }
     }
     $results = array();
     foreach ($data->getClassTypeCredits() as $idx => $ctc) {
         $results[$ctc->getClassType()->getName()] = $ctc;
     }
     $results = array_merge($defaults, $results);
     $payload = array('type' => 'tsk_class_types', 'label' => ' ', 'required' => false, 'data' => $results);
     $form->add($this->factory->createNamed('classTypeCredits', 'collection', NULL, $payload));
 }
 /**
  * Form event - adds entities to uow to be delete
  * 
  * @param DataEvent $event
  */
 public function postBind(DataEvent $event)
 {
     $collection = $event->getData();
     if ($collection instanceof PersistentCollection) {
         foreach ($collection->getDeleteDiff() as $entity) {
             $this->om->remove($entity);
         }
     }
 }
 public function onPostBind(DataEvent $event)
 {
     $contactDetail = $event->getData();
     $country = $contactDetail->getCountry();
     if ($country instanceof Country) {
         $code = (int) $country->getCountryCode();
         $contactDetail->setCountryCode($code);
     }
 }
 public function preSetData(DataEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $data) {
         return;
     }
     $form->add($this->factory->createNamed('password', 'repeated', null, array('first_options' => array('label' => 'form.label.password'), 'second_options' => array('label' => 'form.label.password_repeated'), 'invalid_message' => 'form.error.password_mismatch')));
 }
 /**
  * {@inheritdoc}
  */
 public function validate(DataEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     if ($this->captcha->getLength() !== strlen($data) || $this->captcha->getCode() !== $this->captcha->encode($data)) {
         $form->addError(new FormError('The captcha is invalid'));
     }
     $this->captcha->removeCode();
 }
 public function onBindClientData(DataEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     if ((!$form->hasParent() || $form->getParent()->isRoot()) && !$this->csrfProvider->isCsrfTokenValid($this->intention, $data)) {
         $form->addError(new FormError('The CSRF token is invalid. Please try to resubmit the form'));
         // If the session timed out, the token is invalid now.
         // Regenerate the token so that a resubmission is possible.
         $event->setData($this->csrfProvider->generateCsrfToken($this->intention));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function onBindNormData(DataEvent $event)
 {
     $data = $event->getData();
     if (empty($data)) {
         return;
     }
     $address = $data['address'];
     $latitude = isset($data['latitude']) ? $data['latitude'] : null;
     $longitude = isset($data['longitude']) ? $data['longitude'] : null;
     $locality = isset($data['locality']) ? $data['locality'] : null;
     $country = isset($data['country']) ? $data['country'] : null;
     $geo = new AddressGeolocation($address, $latitude, $longitude, $locality, $country);
     $event->setData($geo);
 }
 public function preBind(DataEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     if (null === $data) {
         return;
     }
     if (isset($data['estado'])) {
         $form->remove('cidade');
         $form->add($this->factory->createNamed('cidade', 'entity', null, array('class' => 'BFOSBrasilBundle:Cidade', 'property' => 'nome', 'query_builder' => function (EntityRepository $er) use($data) {
             return $er->createQueryBuilder('c')->where('c.uf = :uf')->orderBy('c.nome', 'ASC')->setParameter('uf', $data['estado']);
         })));
     }
 }
Beispiel #13
0
 public function preSetData(DataEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $data) {
         return;
     } else {
         $newData = new \Doctrine\Common\Collections\ArrayCollection();
         $newData['id'] = $data->getId();
         $newData['title'] = $data->getTitle();
         $data = $newData;
     }
     return $data;
 }
Beispiel #14
0
 public function preSetData(DataEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     if (null === $data) {
         return;
     } else {
         $newData = new \Doctrine\Common\Collections\ArrayCollection();
         foreach ($data as $item) {
             $newData[] = $item;
         }
         $data = $newData;
     }
     return $data;
 }
 public function prebind(DataEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     $locationService = LocationService::getCurrentInstance();
     $countryId = !empty($data) && $data['country'] ? $data['country'] : 0;
     $choices = array(0 => null);
     if ($countryId) {
         $cities = $locationService->getGlobalCitiesListByContry($countryId);
         foreach ($cities['data'] as $id => $value) {
             $choices[$id] = $value['name'];
         }
     }
     $form->add($this->factory->createNamed('city', GlobalCityListType::NAME, null, compact('choices')));
 }
 /**
  * {@inheritdoc}
  */
 public function onBindNormData(DataEvent $event)
 {
     $data = $event->getData();
     if (empty($data)) {
         return;
     }
     if ($this->multiple) {
         $paths = explode(',', $data);
         $return = array();
         foreach ($paths as $path) {
             if ($handle = $this->getHandleToPath($path)) {
                 $return[] = $handle;
             }
         }
     } else {
         if ($handle = $this->getHandleToPath($data)) {
             $return = $handle;
         }
     }
     $event->setData($return);
 }
 public function preSetData(DataEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     // During form creation setData() is called with null as an argument
     // by the FormBuilder constructor. You're only concerned with when
     // setData is called with an actual Entity object in it (whether new
     // or fetched with Doctrine). This if statement lets you skip right
     // over the null condition.
     if (null === $data) {
         return;
     }
     // check if the product object is "new"
     if ($data->getId()) {
         $form->add($this->factory->createNamed('datetime', 'created_at', null, array('label' => 'Fecha de creación:', 'widget' => 'single_text')))->add($this->factory->createNamed('datetime', 'start_fund_at', null, array('label' => 'Fecha de inicio de recaudación:', 'widget' => 'single_text', 'required' => false)))->add($this->factory->createNamed('datetime', 'extended_at', null, array('label' => 'Fecha de inicio de prorroga:', 'widget' => 'single_text', 'required' => false)))->add($this->factory->createNamed('integer', 'applause', null, array('label' => 'Aplausos:')))->add($this->factory->createNamed('integer', 'status', null, array('label' => 'Estado:')));
     } else {
         //            $builder = $this->factory->createBuilder(new \Crearock\ProjectBundle\Form\ProjectType());
         $builder = $this->factory->createNamedBuilder('checkbox', 'terms', null, array('property_path' => false));
         //            $term_field = $builder->create('terms', 'checkbox', array('property_path' => 'false'))
         $term_field = $builder->addValidator(new CallbackValidator(function ($terms) {
             if (!$terms->getData()) {
                 $terms->addError(new FormError('Debes aceptar los Términos de uso.'));
             }
         }))->getForm();
         $form->add($term_field);
         //            $name = $form->getName();
         //           $form = $this->factory->createNamed(new \Crearock\ProjectBundle\Form\ProjectType(), $name);
         /*            $builder = $this->factory->createBuilder(new \Crearock\ProjectBundle\Form\ProjectType());
                     
                     $builder->addValidator(new CallbackValidator(
                         function (FormInterface $form){
                             $terms = $form->get('terms');
                             if (!$terms->getData()) {
                                 $terms->addError(new FormError('Debes aceptar los Términos de uso.'));
                             }
                         }
                     ));
          */
     }
 }
 public function preSetData(DataEvent $event)
 {
     $data = $event->getData();
     $form = $event->getForm();
     // During form creation setData() is called with null as an argument
     // by the FormBuilder constructor. We're only concerned with when
     // setData is called with an actual Entity object in it (whether new,
     // or fetched with Doctrine). This if statement let's us skip right
     // over the null condition.
     if (null === $data) {
         return;
     }
     // check if the product object is "new"
     if ($data != null) {
         $choicesEntityName = array($data->entityName => $data->entityName);
         $choicesPropertyName = array($data->propertyName => $data->propertyName);
         $form->add($this->factory->createNamed('choice', 'entityName', $data->entityName, array('choices' => $choicesEntityName, 'multiple' => false, 'attr' => array('style' => 'width:120px;margin:0px;', 'class' => 'entityClass'), 'required' => false)));
         $form->add($this->factory->createNamed('choice', 'propertyName', $data->propertyName, array('choices' => $choicesPropertyName, 'multiple' => false, 'attr' => array('style' => 'width:120px;margin:0px;', 'class' => 'propertyClass'), 'required' => false)));
         if ($data->fieldType == 'entity') {
             $form->add($this->factory->createNamed('text', 'length', null, array('attr' => array('style' => 'width:120px;margin:0px;', 'disabled' => 'disabled', 'required' => false))));
         }
     }
 }