0
votes

Well...Everything is in the title and here I am because the documentation about this topic doesn't exist really..So I hope some ninja developers will be able to give me some tips...

I'm working on my personal portfolio (Symfony 2.3) and I have a problem since a couple of week. I used sonata admin bundle to create my admin panel and have a lot of troubles to fix the different file upload in my admin. For that I was wondering to use the PunkAveFileUploaderBundle. But honestly I have no idea of how to implement it properly. I think I have to edit some sonata admin files but here again...which ones? I'm reading the files and have already a good idea of which ones to tweak but not sure at all.. By reading and following the documentation of sonata admin (sonata doc) I never had success.. Don't know why I'm actually following it step by step..

Well if anyone of you has an idea of how to implement the PunkAveFileUpload bundle with sonata admin bundle, let me know your tips or even better, a small example...

PS: links to the documentation are not needed, thank you.

1

1 Answers

0
votes

May be you can read this post about getting Gedmo Uploadable working with Sonata Admin

I think you'll have to pass the punk_ave.file_uploader service in your admin class:

acme.admin.demo:
    class: Acme\DemoBundle\Admin\DemoAdmin
    arguments: [~, Acme\DemoBundle\Entity\Demo, SonataAdminBundle:CRUD, @punk_ave.file_uploader]
    tags:
        - {name: sonata.admin, manager_type: orm, group: demo, label: demo}
    calls:
        - [ setTranslationDomain, [SonataAdminBundle]]

ANd change your DemoAdmin class to manage uploads:

class DemoAdmin extends Admin
{
    /**
     * File uploader
     */
    private $fileUploader = null;

    /**
     * Constructor
     */
    public function __construct($code, $class, $baseControllerName, $fileUploader = null)
    {
        parent::__construct($code, $class, $baseControllerName);
        $this->fileUploader = $fileUploader;
    }

    // ...

    public function prePersist($object)
    {
        $this->manageUploads($object);
    }

    public function preUpdate($object)
    {
        $this->manageUploads($object);
    }

    /**
     * Mannger uploads
     * @param Demo $object
     */
    private function manageUploads($object)
    {
        if ($object->getId()->getFile()) {
            $this->fileUploader->syncFiles(...);
        }
    }
}

I really don't know if this will work, but that's the way I'll try to make it works...