Creates a form to delete a file entity.

@param SakonninFile $file The file entity

@return \Symfony\Component\Form\Form The form
15684
public function createDeleteForm(SakonninFile $file)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('file_delete', array('id' => $file->getId())))
            ->setMethod('DELETE')
            ->getForm()
        ;
    }
420848
public function removeFile(\Enhavo\Bundle\MediaBundle\Entity\File $file)
    {
        $this->files->removeElement($file);
    }
803608
private function removeUniqueFile($file)
    {
        if (!isset($this->manifest[$file])) {
            return;
        }

        // delete unique file
        $uniqueFile = public_path($this->manifest[$file]);
        if ($uniqueFile !== null && file_exists($uniqueFile)) {
            unlink($uniqueFile);
        }

        // update manifest
        unset($this->manifest[$file]);
        if (file_put_contents($this->manifestFile, '<?php return ' . var_export($this->manifest, true) . ';' . PHP_EOL, LOCK_EX) === false) {
            throw new RuntimeException(sprintf('Asset Manager was not able to save manifest file "%s"', $this->manifestFile)); // @codeCoverageIgnore
        }
    }
865878
public function setFile($file = null)
    {
        if (is_null($file)) {
            $this->file = ['name' => date('Ymd-His'), 'part' => 1];
        } else {
            if (!array_key_exists("name", $file) && !array_key_exists("part", $file)) {
                $this->file = $file['1'];
            } else {
                $this->file = $file;
            }
        }
        return $this;
    }
539160
public static function createFromUploadedFile(UploadedFile $file)
    {
        $asset = new Asset();
        $guesser = MimeTypeGuesser::getInstance();
        return $asset
            ->setFilename($file->getFilename())
            ->setExtension($file->getExtension())
            ->setPathname($file->getPathname())
            ->setMimeType($guesser->guess($file->getPathname()))
            ->setClientOriginalName($file->getClientOriginalName())
            ->setClientOriginalExtension($file->getClientOriginalExtension())
            ->setClientMimeType($file->getClientMimeType())
        ;
    }
818854
public function make($file)
    {
        if ($file instanceof SymfonyUploadedFile) {
            return $this->createFromObject($file);
        }

        if (is_array($file)) {
            if (isset($file['base64']) && isset($file['name'])) {
                return $this->createFromBase64($file['name'], $file['base64']);
            }
            else {
                return $this->createFromArray($file);
            }
        }

        if (array_key_exists('scheme', parse_url($file))) {
            return $this->createFromUrl($file);
        }

        return $this->createFromString($file);
    }
558250
public static function fromExisting(IFile $file) : File
    {
        if ($file instanceof self) {
            return $file;
        } elseif ($file instanceof IUploadedImage) {
            return new UploadedImage($file->getFullPath(), $file->getUploadError(), $file->getClientFileName(), $file->getClientMimeType());
        } elseif ($file instanceof IUploadedFile) {
            return new UploadedFile($file->getFullPath(), $file->getUploadError(), $file->getClientFileName(), $file->getClientMimeType());
        } elseif ($file instanceof IImage) {
            return new Image($file->getFullPath(), $file->getClientFileName());
        } else {
            return new self($file->getFullPath(), $file->getClientFileName());
        }
    }
605871
public function writeLazaret(File $file)
    {
        $lazaretPathname = $this->booker->bookFile($file->getOriginalName());
        $this->filesystem->copy($file->getFile()->getRealPath(), $lazaretPathname, true);

        $lazaretPathnameThumb = $this->booker->bookFile($file->getOriginalName(), 'thumb');
        try {
            $this->alchemyst->turnInto($file->getFile()->getPathname(), $lazaretPathnameThumb, $this->createThumbnailSpecification());
        } catch (ExceptionInterface $e) {
            // Ignore, an empty file should be present
        }

        return new PersistedLazaretInformation($lazaretPathname, $lazaretPathnameThumb);
    }
757240
public function save($file = null)
    {
        //argument 1 must be a file or null
        Argument::i()->test(1, 'string', 'null');
        
        if (is_null($file)) {
            $file = $this->file;
        }
        
        if (is_null($file)) {
            Exception::i()
                ->setMessage(Argument::INVALID_ARGUMENT)
                ->addVariable(1)
                ->addVariable(__CLASS__.'->'.__FUNCTION__)
                ->addVariable('file or null')
                ->addVariable($file)
                ->setTypeLogic()
                ->trigger();
        }
        
        File::i($file)->setData($this->language);
        
        return $this;
    }
1029367
public function deleteAction(Request $request, SakonninFile $file, $access)
    {
        $form = $this->createDeleteForm($file);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrineManager();
            $em->remove($file);
            $em->flush();
            if ($back = $request->request->get('back'))
                return $this->redirect($back);
        }

        return $this->redirectToRoute('file_index');
    }
1188126
public function editAction(Request $request, SakonninFile $file, $access)
    {
        $deleteForm = $this->createDeleteForm($file);
        $editForm = $this->createForm('BisonLab\SakonninBundle\Form\SakonninFileType', $file);
        $editForm->handleRequest($request);

        if ($editForm->isSubmitted() && $editForm->isValid()) {
            $this->getDoctrineManager()->flush();

            return $this->redirectToRoute('file_edit', array('id' => $file->getId()));
        }

        return $this->render('BisonLabSakonninBundle:SakonninFile:edit.html.twig',
            array(
            'file' => $file,
            'edit_form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ));
    }
1240075
public function deleteFile($file)
    {
        if (!$this->filesystem->has($file)) {
            return;
        }

        $this->filesystem->delete($file);
        $this->cacheManager->remove($file);
    }
433662
public static function createFromUploadedFile(UploadedFile $file)
    {
        $size = getimagesize($file->getRealPath());

        $image = new Image($file->guessExtension());
        $image->setOriginalFilename($file->getClientOriginalName());
        $image->setMimeType($file->getMimeType());
        $image->setSize(filesize($file->getRealPath()));
        $image->setWidth($size[0]);
        $image->setHeight($size[1]);

        return $image;
    }
181766
public static function rmfile($file)
    {
        if (is_file($file)) {
            return chmod($file, 0777) && unlink($file);
        } else {
            throw new RuntimeException(sprintf(
                'Invalid file path supplied "%s"', $file
            ));
        }
    }
764168
protected function customiseFile(File $file)
    {
        $customizedfile = $file->customise(array(
            'UploadFieldThumbnailURL' => $this->getThumbnailURLForFile($file),
            'UploadFieldDeleteLink' => $this->getItemHandler($file->ID)->DeleteLink(),
            'UploadFieldEditLink' => $this->getItemHandler($file->ID)->EditLink(),
            'UploadField' => $this
        ));

        // render file buttons
        return $customizedfile->customise(array(
                'UploadFieldFileButtons' => (string) $file->renderWith($this->getTemplateFileButtons(), array(
                    'IconRemove' => $this->IconRemove(),
                    'IconEdit' => $this->IconEdit(),
                    'EditEnabled' => $this->EditEnabled(),
                ))
        ));
    }
311379
private function removeFile(File $file)
	{
		$this->removeFileInFileSystem($file);

		if ($file instanceof Image) {
			$em = $this->getDoctrineEntityManager();
			$imageSizeCn = ImageSize::CN();
			$em->createQuery("DELETE FROM $imageSizeCn s WHERE s.master = :master")
				->setParameter('master', $file->getId())
				->execute();
		}

		$entityManager = $this->getDoctrineEntityManager();
		$entityManager->remove($file);
		$entityManager->flush();
	}
1319221
public function add($file)
    {
        if ($file instanceof SplFileInfo) {
            throw InvalidArgumentException::create(
                sprintf(
                    '%1$s/FileBag|%1$s/File[]|%1$s/File',
                    __NAMESPACE__
                ),
                $file
            );
        }

        return parent::add($file);
    }