PHPackages                             a2lix/auto-form-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. a2lix/auto-form-bundle

ActiveSymfony-bundle[Templating &amp; Views](/categories/templating)

a2lix/auto-form-bundle
======================

Automate form building

1.0.1(2mo ago)873.8M↓13.2%33[1 issues](https://github.com/a2lix/AutoFormBundle/issues)10MITPHPPHP &gt;=8.4CI passing

Since Aug 10Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/a2lix/AutoFormBundle)[ Packagist](https://packagist.org/packages/a2lix/auto-form-bundle)[ Docs](https://github.com/a2lix/AutoFormBundle)[ RSS](/packages/a2lix-auto-form-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (42)Versions (25)Used By (10)

A2lix AutoForm Bundle
=====================

[](#a2lix-autoform-bundle)

[![Latest Stable Version](https://camo.githubusercontent.com/927eff08d003c73d3f8c874a4ffde1664dd30ff9d9cf7c5359620874e87eaf88/68747470733a2f2f706f7365722e707567782e6f72672f61326c69782f6175746f2d666f726d2d62756e646c652f762f737461626c65)](https://packagist.org/packages/a2lix/auto-form-bundle)[![Latest Unstable Version](https://camo.githubusercontent.com/20e003f77990ff8e9e34023d2facb6e8313d498265f4c76dd3098b63ba9a2d3a/68747470733a2f2f706f7365722e707567782e6f72672f61326c69782f6175746f2d666f726d2d62756e646c652f762f756e737461626c65)](https://packagist.org/packages/a2lix/auto-form-bundle)[![Total Downloads](https://camo.githubusercontent.com/1edc955a571e8db1d6d62763d5c43105bd3cf48ac9329677f184e4a48cb82cbc/68747470733a2f2f706f7365722e707567782e6f72672f61326c69782f6175746f2d666f726d2d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/a2lix/auto-form-bundle)[![License](https://camo.githubusercontent.com/3d0a924fdbad948c8dfefa2812b31626876290be6109805e29ddfeb9ded2f261/68747470733a2f2f706f7365722e707567782e6f72672f61326c69782f6175746f2d666f726d2d62756e646c652f6c6963656e7365)](https://packagist.org/packages/a2lix/auto-form-bundle)[![Build Status](https://github.com/a2lix/AutoFormBundle/actions/workflows/ci.yml/badge.svg)](https://github.com/a2lix/AutoFormBundle/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/d481346a5505e0f0825ed2cdedd846376bc1954c26328d1e840fa164f3b0315a/68747470733a2f2f636f6465636f762e696f2f67682f61326c69782f4175746f466f726d42756e646c652f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/a2lix/AutoFormBundle)

Stop writing boilerplate form code. This bundle provides a single, powerful `AutoType` form type that automatically generates a complete Symfony form from any PHP class.

Note

If you need to manage form translations, please see the [A2lix TranslationFormBundle](https://github.com/a2lix/TranslationFormBundle), which is designed to work with this bundle.

Tip

A complete demonstration is also available at [a2lix/demo](https://github.com/a2lix/Demo).

Installation
------------

[](#installation)

Use Composer to install the bundle:

```
composer require a2lix/auto-form-bundle
```

Basic Usage
-----------

[](#basic-usage)

The simplest way to use `AutoType` is directly in your controller. It will generate a form based on the properties of the entity or DTO you pass it.

```
// ...

class TaskController extends AbstractController
{
    public function new(Request $request): Response
    {
        $task = new Task(); // Any entity or DTO
        $form = $this
            ->createForm(AutoType::class, $task)
            ->add('save', SubmitType::class)
            ->handleRequest($request)
        ;

        // ...
    }
}
```

How It Works
------------

[](#how-it-works)

`AutoType` reads the properties of the class you provide in the `data_class` option. For each property, it intelligently configures a corresponding form field. This gives you a solid foundation that you can then customize in two main ways:

1. **Form Options:** Pass a configuration array directly when you create the form.
2. **PHP Attributes:** Add `#[AutoTypeCustom]` attributes directly to the properties of your entity or DTO.

Options passed directly to the form will always take precedence over attributes.

Customization via Form Options
------------------------------

[](#customization-via-form-options)

This is the most flexible way to configure your form. Here is a comprehensive example:

```
// ...

class TaskController extends AbstractController
{
    public function new(Request $request, FormFactoryInterface $formFactory): Response
    {
        $product = new Product(); // Any entity or DTO
        $form = $formFactory->createNamed('product', AutoType::class, $product, [
            // 1. Optional define which properties should be excluded from the form.
            // Use '*' for an "exclude-by-default" strategy.
            'children_excluded' => ['id', 'internalRef'],

            // 2. Optional define which properties should be rendered as embedded forms.
            // Use '*' to embed all relational properties.
            'children_embedded' => static fn (mixed $current) => [...$current, 'category', 'tags'],

            // 3. Optional customize, override, or add fields.
            'children' => [
                // Override an existing property with new options
                'description' => [
                    'child_type' => TextareaType::class, // Force a specific form type
                    'label' => 'Product Description', // Standard form options
                    'priority' => 10,
                ],

                // Add a field that does not exist on the DTO/entity
                'terms_and_conditions' => [
                    'child_type' => CheckboxType::class,
                    'mapped' => false,
                    'priority' => -100,
                ],

                // Completely replace a field's builder with a callable
                'price' => function(FormBuilderInterface $builder, array $propAttributeOptions): FormBuilderInterface {
                    // The callable receives the main builder and any options from a potential attribute.
                    // It must return a new FormBuilderInterface instance.
                    return $builder->create('price', MoneyType::class, ['currency' => 'EUR']);
                },

                // Add a new field to the form
                'save' => [
                    'child_type' => SubmitType::class,
                ],
            ],

            // 4. Optional final modifications on the complete form builder.
            'builder' => function(FormBuilderInterface $builder, array $classProperties): void {
                // This callable runs after all children have been added.
                if (isset($classProperties['code'])) {
                    $builder->remove('code');
                }
            },
        ])->handleRequest($request);

        // ...
    }
}
```

Customization via `#[AutoTypeCustom]` Attribute
-----------------------------------------------

[](#customization-via-autotypecustom-attribute)

For a more declarative approach, you can place the configuration directly on the properties of your DTO or entity. This keeps the form configuration co-located with your data model.

```
use A2lix\AutoFormBundle\Form\Attribute\AutoTypeCustom;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;

class Product
{
    #[AutoTypeCustom(excluded: true)]
    public private(set) int $id;

    public ?string $name = null;

    #[AutoTypeCustom(type: TextareaType::class, options: ['attr' => ['rows' => 5]])]
    public ?string $description = null;

    #[AutoTypeCustom(embedded: true)]
    public Category $category;
}
```

### Conditional Fields with Groups

[](#conditional-fields-with-groups)

You can conditionally include fields based on groups, similar to how Symfony's `validation_groups` work. This is useful for having different versions of a form (e.g., a "creation" version vs. an "edition" version).

To enable this, pass a `children_groups` option to your form. This option specifies which groups of fields should be included.

```
$form = $this->createForm(AutoType::class, $product, [
    'children_groups' => ['product:edit'],
]);
```

You can then assign fields to one or more groups using either form options or attributes.

#### Via Form Options

[](#via-form-options)

Use the `child_groups` option within the `children` configuration:

```
// ...
'children' => [
    'name' => [
        'child_groups' => ['product:edit', 'product:create'],
    ],
    'stock' => [
        'child_groups' => ['product:edit'],
    ],
],
// ...
```

In this example, if `children_groups` is set to `['product:edit']`, both `name` and `stock` will be included. If it's set to `['product:create']`, only `name` will be included.

#### Via `#[AutoTypeCustom]` Attribute

[](#via-autotypecustom-attribute)

Use the `groups` property on the attribute:

```
use A2lix\AutoFormBundle\Form\Attribute\AutoTypeCustom;

class Product
{
    #[AutoTypeCustom(groups: ['product:edit', 'product:create'])]
    public ?string $name = null;

    #[AutoTypeCustom(groups: ['product:edit'])]
    public ?int $stock = null;
}
```

If no `children_groups` option is provided to the form, all fields are included by default, regardless of whether they have groups assigned.

Advanced Recipes
----------------

[](#advanced-recipes)

### Creating a Compound Field with `inherit_data`

[](#creating-a-compound-field-with-inherit_data)

You can use a callable in the `children` option to create complex fields that map to the parent object, which is useful for things like date ranges.

```
'children' => [
    '_' => function (FormBuilderInterface $builder): FormBuilderInterface {
        return $builder
            ->create('validity_range', FormType::class, ['inherit_data' => true])
                ->add('startsAt', DateType::class, [/* ... */])
                ->add('endsAt', DateType::class, [/* ... */]);
    },
]
```

Global Configuration
--------------------

[](#global-configuration)

While not required, you can configure the bundle globally. For example, you can define a list of properties to always exclude.

Create a configuration file in `config/packages/a2lix_auto_form.yaml`:

```
a2lix_auto_form:
    # Exclude 'id' and 'createdAt' properties from all AutoType forms by default
    children_excluded: [id, createdAt]
```

License
-------

[](#license)

This package is available under the [MIT license](LICENSE).

###  Health Score

70

—

ExcellentBetter than 100% of packages

Maintenance84

Actively maintained with recent releases

Popularity59

Moderate usage in the ecosystem

Community30

Small or concentrated contributor base

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 72.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~151 days

Recently: every ~34 days

Total

24

Last Release

81d ago

Major Versions

0.4.8 → 1.0.0-beta.12025-10-14

PHP version history (7 changes)0.1-beta.1PHP ^5.4 || ^7.0

0.1-beta.2PHP ^7.1.3

0.3.1PHP ^7.2

0.3.2PHP &gt;=7.2.5

0.4.5PHP ^8.1

1.0.0-beta.1PHP &gt;=8.2

1.0.0-beta.2PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8ea80b64b7094cfdba2423bc828bb3bdef0a8e4a569d2c600723885ce5fc9b4b?d=identicon)[a2lix](/maintainers/a2lix)

---

Top Contributors

[![webda2l](https://avatars.githubusercontent.com/u/517753?v=4)](https://github.com/webda2l "webda2l (29 commits)")[![tchapi](https://avatars.githubusercontent.com/u/1944007?v=4)](https://github.com/tchapi "tchapi (2 commits)")[![jordisala1991](https://avatars.githubusercontent.com/u/1137485?v=4)](https://github.com/jordisala1991 "jordisala1991 (2 commits)")[![liarco](https://avatars.githubusercontent.com/u/1532277?v=4)](https://github.com/liarco "liarco (1 commits)")[![ABGEO](https://avatars.githubusercontent.com/u/19558543?v=4)](https://github.com/ABGEO "ABGEO (1 commits)")[![petrspevak](https://avatars.githubusercontent.com/u/42165749?v=4)](https://github.com/petrspevak "petrspevak (1 commits)")[![tobias-93](https://avatars.githubusercontent.com/u/3901745?v=4)](https://github.com/tobias-93 "tobias-93 (1 commits)")[![nexxome](https://avatars.githubusercontent.com/u/2526962?v=4)](https://github.com/nexxome "nexxome (1 commits)")[![bresam](https://avatars.githubusercontent.com/u/52054015?v=4)](https://github.com/bresam "bresam (1 commits)")[![deguif](https://avatars.githubusercontent.com/u/993399?v=4)](https://github.com/deguif "deguif (1 commits)")

---

Tags

bundlephpsymfonysymfony-bundlesymfony-formsymfonyautomationformfieldautomagicbuildingautomate

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/a2lix-auto-form-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/a2lix-auto-form-bundle/health.svg)](https://phpackages.com/packages/a2lix-auto-form-bundle)
```

###  Alternatives

[nelmio/api-doc-bundle

Generates documentation for your REST API from attributes

2.3k63.6M233](/packages/nelmio-api-doc-bundle)[a2lix/translation-form-bundle

Translate your doctrine objects easily with some helpers

3376.9M38](/packages/a2lix-translation-form-bundle)[pugx/autocompleter-bundle

Add an autocomplete type to forms

93861.6k3](/packages/pugx-autocompleter-bundle)[craue/formflow-bundle

Multi-step forms for your Symfony project.

7484.0M13](/packages/craue-formflow-bundle)[qossmic/rich-model-forms-bundle

Provides additional data mapper options that ease the use of the Symfony Form component with rich models.

218278.7k](/packages/qossmic-rich-model-forms-bundle)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
