/** * Copy image to temporary directory * * @param FilterDataEvent $event * @return void */ public function preSetData(FormEvent $event) { $entity = $event->getData(); if ($entity instanceof ImageInterface && null !== $entity->getId()) { try { $this->imageManager->copyImagesToTemporaryDirectory($entity); } catch (\Gaufrette\Exception\FileNotFound $e) { $event->setData(null); } } }
/** * Copy images from permenent to temporary directory * * @param FormEvent $event */ public function postSetData(FormEvent $event) { $collection = $event->getData(); $form = $event->getForm(); if ($collection instanceof PersistentCollection) { foreach ($collection as $key => $image) { if ($image instanceof MultiImageInterface && null !== $image->getId()) { try { $this->imageManager->copyImagesToTemporaryDirectory($image); } catch (\Gaufrette\Exception\FileNotFound $e) { $form->remove($key); $collection->removeElement($image); } } } } }