1. Requirement

  • Symfony >= 3.4

2. Installation

Use composer

composer require a2lix/auto-form-bundle

After the successful installation, add/check the bundle registration

// Symfony >= 4.0 in bundles.php
// ...
A2lix\AutoFormBundle\A2lixAutoFormBundle::class => ['all' => true],
// ...

// Symfony >= 3.4 in AppKernel::registerBundles()
$bundles = array(
// ...
new A2lix\AutoFormBundle\A2lixAutoFormBundle(),
// ...

3. Configuration

There is no minimal configuration, so this part is optionnal. Full list:

// Symfony >= 4.0. Create a dedicated a2lix.yaml in config/packages with:
// Symfony >= 3.4. Add in your app/config/config.yml:

a2lix_auto_form:
    excluded_fields: [id, locale, translatable]       # [1]
  • [1] Optionnal.

4. Usage

In a classic formType

use A2lix\AutoFormBundle\Form\Type\AutoFormType;
...
$builder->add('medias', AutoFormType::class);

Advanced examples

use A2lix\AutoFormBundle\Form\Type\AutoFormType;
...
$builder->add('medias', AutoFormType::class, [
    'fields' => [                               // [2]
        'description' => [                         // [3.a]
            'field_type' => 'textarea',                // [4]
            'label' => 'descript.',                    // [4]
            'locale_options' => [                  // [3.b]
                'es' => ['label' => 'descripciĆ³n']     // [4]
                'fr' => ['display' => false]           // [4]
            ]
        ]
    ],
    'excluded_fields' => ['details']            // [2]
]);
  • [2] Optionnal. If set, override the default value from config.yml
  • [3] Optionnal. If set, override the auto configuration of fields
  • [3.a] Optionnal. - For a field, applied to all locales
  • [3.b] Optionnal. - For a specific locale of a field
  • [4] Optionnal. Common options of symfony forms (max_length, required, trim, read_only, constraints, ...), which was added 'field_type' and 'display'

5. Additional

Example

See Demo Bundle for more examples.