Copy media to temporary directory

@param FormEvent $event
@return void
498037
public function preSetData(FormEvent $event)
    {
        $entity = $event->getData();
    
        if ($entity instanceof FileInterface && null !== $entity->getId()){
            try {
                $this->fileManager->copyFileToTemporaryDirectory($entity);
            } catch (\Gaufrette\Exception\FileNotFound $e) {
                $event->setData(null);
            }
        }
    }
1047139
protected function getCreationEvent($formData)
    {
        $contentCreateEvent = new ContentCreateEvent();

        $contentCreateEvent
            ->setLocale($formData['locale'])
            ->setDefaultFolder($formData['default_folder'])
            ->setTitle($formData['title'])
            ->setVisible($formData['visible'])
        ;

        return $contentCreateEvent;
    }
358940
public function onCreateForm(CreateFormResourceEvent $event)
    {
        $form = $this->container->get('form.factory')->create(new FileType(true), new File());
        $content = $this->container->get('templating')->render(
            'ClarolineCoreBundle:Resource:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => 'file'
            )
        );
        $event->setResponseContent($content);
        $event->stopPropagation();
    }
1065645
private function setFormTheme(FormView $formView, array $theme): void
    {
        $this->get('twig')->getRuntime(FormRenderer::class)->setTheme($formView, $theme);
    }
929139
public function convertColour(FormEvent $event)
    {
        if (empty($event->getData()))
            $event->setData('#000000');

        $event->setData(ColourValidator::isColour($event->getData()));
    }
393991
public function onCopy(CopyResourceEvent $event)
    {
        /** @var File $webResource */
        $webResource = $event->getResource();

        $file = $this->copy($webResource, $event->getCopy());
        $event->setCopy($file);
        $event->stopPropagation();
    }
229253
public function store(ImageFormRequest $request, Event $event): void
    {
        $event->addMediaFromRequest('file')
             ->sanitizingFileName(function ($fileName) {
                 return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION);
             })
             ->toMediaCollection('default', config('cortex.bookings.media.disk'));
    }
1318188
public function processRedirectAfterPublish(FormActionEvent $event): void
    {
        if ($event->getForm()['redirectUrlAfterPublish']->getData()) {
            return;
        }

        $this->resolveSystemUrlRedirect($event);
    }
807060
public function postSubmit(FormEvent $event)
    {
        if ($event->getForm()->isRoot()) {
            // Collect the submitted data of each form
            $this->dataCollector->collectSubmittedData($event->getForm());

            // Assemble a form tree
            // This is done again after the view is built, but we need it here as the view is not always created.
            $this->dataCollector->buildPreliminaryFormTree($event->getForm());
        }
    }
217334
public function onCreateForm(CreateFormResourceEvent $event)
    {
        $form = $this->formFactory->create(new DirectoryType, new Directory());
        $response = $this->templating->render(
            'ClarolineCoreBundle:Resource:createForm.html.twig',
            array(
                'form' => $form->createView(),
                'resourceType' => 'directory'
            )
        );
        $event->setResponseContent($response);
        $event->stopPropagation();
    }
398175
public function postSubmit(FormEvent $event)
    {
        $image = $event->getData();

        if ($image && $image->hasFile()) {
            $image->setPath(null);
        }
    }
391935
public function preSubmit(FormEvent $event): void
    {
        $rawData = $event->getData();
        $form = $event->getForm();
        $data = $form->getData();

        Assert::isInstanceOf($data, CustomerInterface::class);

        // if email is not filled in, go on
        if (!isset($rawData['email']) || empty($rawData['email'])) {
            return;
        }

        /** @var CustomerInterface|null $existingCustomer */
        $existingCustomer = $this->customerRepository->findOneBy(['email' => $rawData['email']]);
        if (null === $existingCustomer || null !== $existingCustomer->getUser()) {
            return;
        }

        $existingCustomer->setUser($data->getUser());
        $form->setData($existingCustomer);
    }
146573
public function postSetData(FormEvent $event)
    {
        $collection = $event->getData();
        $form = $event->getForm();

        if ($collection instanceof PersistentCollection){
            foreach ($collection as $key => $file){
                if ($file instanceof MultiFileInterface){
                    try {
                        $this->fileManager->copyFileToTemporaryDirectory($file);
                    } catch (\Gaufrette\Exception\FileNotFound $e) {
                        $form->remove($key);
                        $collection->removeElement($file);
                    }
                }
            }
        }
    }
869184
public function submit(FormEvent $event)
    {
        $image = $event->getData();

        if ($image && $image->isNew() && !$image->hasFile()) {
            $event->setData(null);
        }
    }
937379
public function changeData(FormEvent $event)
    {
        $data = $event->getData();

        if (null === $data) {
            $data = array();
        }

        if ($data instanceof \Doctrine\Common\Collections\Collection) {
            $event->setData($data->getValues());
        } else {
            $event->setData(array_values($data));
        }
    }
450987
public function buildCollection(FormEvent $event, $eventName)
    {
        $form = $event->getForm();

        for ($i = 0; $i < $this->options['max_items']; ++$i) {
            $required = $i < $this->options['min_items'] ? true : false;
            $displayed = $i < $this->options['min_items'] || $this->isDisplayable($event, $i, $eventName);

            $options = $this->options['options'];
            $options['required'] = isset($options['required']) ?
                $options['required'] && $required :
                $required
            ;
            $options['attr'] = array_replace(
                isset($options['attr']) ? $options['attr'] : array(),
                array(
                    'data-collection-id' => $this->options['collection_id'],
                    'data-display' => $displayed ? 'show' : 'hide',
                    'data-position' => $i,
                )
            );

            if (!$displayed) {
                self::disableConstraints($options);
            }

            $form->add($i, $this->options['type'], $options);

            $form->get($i)->add('__to_remove', CheckboxType::class, array(
                'mapped' => false,
                'required' => false,
                'data' => !$displayed,
                'attr' => array(
                    'class' => 'idci_collection_item_remove',
                ),
            ));
        }
    }
230890
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);
                    }
                    
                }
            }
        }
    }