/** * {@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 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); }
/** * {@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); }