2

Im pretty new in symfony. Now i have new project an i need a advice, what technlogy to choose. I spotted, that symfony4 almost all demos installs easy_admin and it looks like good choice. But now for few days im struggling with some issues and lack of documentation, information. So i want to know - is my idea possible in easy admin in easy way (not writing almost everythong custom) and i just cannot find proper documentation or i need to chose another solution (any suggestions?)

So i have database with one table, which have more than 10 related tables. When i create new base entity i want to add all related entities in one window. And exactly add, not chose from already prepared, because i need to done job in one form, not move between more than 10 forms to make one record (customer doesnt care about relations). Maye i can create base record and on edit add all related entities. And related entities can be almost every type - OneToOne OnetoMany ManytoMany.

So i really need advice, how this job can be done, because i tried multiple ways in relations and i can only choose from already inserted records, but cannot add new. All related entities have multiple input fields - it needs full form generated.

Tilo
  • 51
  • 3
  • I want 2 know - is this possible, because none of documentation reveals this. So dunno what code exactly you want? – Tilo Jan 29 '18 at 09:52

2 Answers2

1

Created sample project, awailable on github Web Forest Goal is make clear manual, how to do things not fully explained in official EasyAdmin manual or demo.

Project goal nr.1: achieve all related entities insert from one Forest insert and/or edit form. All types - OneToOne, OneToMany, ManyToMany. Explain for novices, what exactly we do wrong and how to do thing more clearly.

Please feel free - comment, commit changes, add more features.

Tilo
  • 51
  • 3
1

You need to create custom form class and reference it in yaml config file through entry_type option. For example, imagine that User entity has related entity UserSettings (with fields code and value) and you want to edit these settings right in the User edit form:

Form class:

class UserSettingsType extends AbstractType
{

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => UserSettings::class
        ]);
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('code')
            ->add('value');
    }
}

YAML config:

easy_admin:
    entities:
        User:
            class: App\Entity\User
            edit:
                fields:
                    - ...
                    - { property: 'settings', type: 'collection', type_options: { entry_type: 'App\Form\EasyAdmin\UserSettingsType' , ... }}

I've stumbled upon this solution in this question

kudlohlavec
  • 464
  • 4
  • 18