/**
  * 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);
         }
     }
 }
 /**
  * Checks if images is modified by some other user
  *
  * @param ImageInterface $entity
  * @param string $hash
  * @throws FileHashChangedException
  */
 protected function checksum(ImageInterface $entity)
 {
     $currentHash = $this->imageManager->checksumTemporaryFileByName($entity->getName());
     if ($entity->getHash() !== $currentHash) {
         throw new FileHashChangedException($entity->getName());
     }
 }
 /**
  * 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);
                 }
             }
         }
     }
 }