Pedro Tentugal
Pedro Tentugal

Reputation: 94

How to add multiple images to edit form using MongoDB in Sonata?

I'm trying to find out how I can have the edit action of a Document (Entity) that is using an array of Object IDs to store the ID of an image stored using GridFS. This is a one-to-many but using an array inside the Document, instead of a middle table.

So far I was able to add the following to my edit action: Images Manager for my News entity/document

Here is the code I've used in the NewsAdmin configureFormFields():

$formMapper
        ->with('Images Manager')
        ->add(
            'cover_images',
            CollectionType::class,
            ['required' => true, 'label' => 'Cover Images'],
            [ 'admin_code' => 'admin.file' ]
        )

I have a controller and an action (@Route("/image/{id}", name="show_image")) that handles the display of images in the frontend using MongoDB GridFS. It uses the IDs stored in this array: Example of Array of Object IDs

Upvotes: 1

Views: 75

Answers (0)

Related Questions