1

I need to customize a form view field (edit form field) in EasyAdmin bundle. Here's how it's done in the list view: - { property: 'images', template: 'custom_template.html.twig'}

How to implement the same thing in the form view (edit mode)? Custom templates don't work for the form view (edit view). So I made a custom field type

- { property: 'images', type: 'App\Form\Type\MyImagesType'}

but don't know how to implement a custom template to it.

class MyImagesType extends CollectionType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $form->add($key, FileType::class, ['multiple'=>true, 'required'=>false]);
 }
}

I want to integrate dopzone.js in my form by inserting the script:

<script src="./public/dropzone.js"></script>
<form action="{{ oneup_uploader_endpoint('gallery') }}" class="dropzone" style="width:200px; height:200px; border:4px dashed black">
</form>
7cart project
  • 317
  • 1
  • 4
  • 13

2 Answers2

3

EasyAdmin relies on Symfony's Form component for anything related to edit/new views. That means that the simple mechanism used in list/show/search to customize the rendering of each property is not available.

As explained in https://symfony.com/doc/master/bundles/EasyAdminBundle/book/edit-new-configuration.html#advanced-design-configuration the alternative is either to override the default templates or create your own form theme.

Hopefully Symfony will make this simpler soon when this proposal is approved and merged: https://github.com/symfony/symfony/issues/29651

Javier Eguiluz
  • 3,987
  • 2
  • 23
  • 44
0

like this:

# config/packages/easy_admin.yaml
easy_admin:
    entities:
        Customer:
            class: App\Entity\Customer
            form:  # <-- 'form' is applied to both 'new' and 'edit' views
                fields:
                    - 'id'
                    - { property: 'email', type: 'email', label: 'Contact' }
                    # ...
    # ...

check the documentation, its very easy https://symfony.com/doc/master/bundles/EasyAdminBundle/book/edit-new-configuration.html#the-special-form-view

hoover_D
  • 620
  • 4
  • 9