PHPackages                             kikwik/json-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. kikwik/json-form-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

kikwik/json-form-bundle
=======================

Helpers and listeners for using forms with dunglas/doctrine-json-odm

v1.0.4(1y ago)123MITPHPPHP &gt;=8.1

Since Nov 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/kikwik/json-form-bundle)[ Packagist](https://packagist.org/packages/kikwik/json-form-bundle)[ RSS](/packages/kikwik-json-form-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (6)Used By (0)

KikwikJsonFormBundle
====================

[](#kikwikjsonformbundle)

Helpers and listeners for using forms with [dunglas/doctrine-json-odm](https://github.com/dunglas/doctrine-json-odm)

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

[](#installation)

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

```
$ composer require kikwik/json-form-bundle
```

Usage
-----

[](#usage)

Suppose to have some models defined:

```
// first model
namespace App\Model;

class Dimension
{
    private ?int $height = null;
    private ?int $width = null;

    // getter and setter...
}
```

```
// second model
namespace App\Model;

class TechData
{
    private ?string $someData = null;
    private ?string $otherData = null;

    // getter and setter...
}
```

Then you have to define a form for each model:

```
// first model form
namespace App\Form\Model;

use App\Model\Dimension;

class DimensionType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('height')
            ->add('width')
        ;
    }

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

```
// second model form
namespace App\Form\Model;

use App\Model\TechData;

class TechDataType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('someData')
            ->add('otherData')
        ;
    }

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

Now you can to have an entity with some `json_document` fields defined as single model or an array of arbitrary models (the entity must have an `updatedAt` timestamp field)

```
// the entity
namespace App\Entity;

use App\Model\Dimension;

#[ORM\Entity(repositoryClass: ProductRepository::class)]
class Product
{
    #[ORM\Column(type: Types::STRING)]
    private ?string $name = null;

    #[ORM\Column(type: 'json_document', nullable: true)]
    private ?Dimension $dimension = null;

    #[ORM\Column(type: 'json_document', nullable: true)]
    private array $techData = [];

    #[ORM\Column(type: Types::DATETIME_MUTABLE)]
    protected $updatedAt;

    // getter and setter...
}
```

To handle correctly forms that has `json_document` fields you must autowire the `JsonDocumentFormSubscriber` service and add to the FormBuilderInterface as event subscriber.

The subscriber will set the `updatedAt` field to the current timestamp in case of one of the json\_document fields has changed. This will force doctrine to persist the main entity.

```
// the entity form
namespace App\Form;

use Kikwik\JsonFormBundle\EventListener\JsonDocumentFormSubscriber;

class ProductFormType extends AbstractType
{
    public function __construct(private JsonDocumentFormSubscriber $jsonDocumentFormSubscriber) # autowire here
    {
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name')
            ->add('dimension',DimensionType::class)
            ->addEventSubscriber($this->jsonDocumentFormSubscriber) # add as event subscriber
        ;
    }

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

JsonDocumentCollectionType
--------------------------

[](#jsondocumentcollectiontype)

To handle collections of models you must define the mapping from a model to the relative form in `config/packages/kikwik_json_form.yaml`:

```
kikwik_json_form:
    model_map:
        App\Model\Dimension:    App\Form\Model\DimensionType
        App\Model\TechData:     App\Form\Model\TechDataType
```

Then you can use the `JsonDocumentCollectionType` to store heterogeneous types of models in one field:

```
namespace App\Form;

use Kikwik\JsonFormBundle\EventListener\JsonDocumentFormSubscriber;

class ProductFormType extends AbstractType
{
    public function __construct(private JsonDocumentFormSubscriber $jsonDocumentFormSubscriber)
    {
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name')
            ->add('techData',JsonDocumentCollectionType::class, [
                'model_labels' => [
                    'App\Model\Dimension' => 'Size of product',
                    'App\Model\TechData' => 'Technical data',
                ],
                'model_options' => [
                    'App\Model\Dimension' => ['unitOfMeasurement'=>'mm'],
                ]
            ])
            ->addEventSubscriber($this->jsonDocumentFormSubscriber)
        ;
    }

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

To force the initial data use the `data_models` option inside a `PRE_SET_DATA` listener:

```
namespace App\Form;

use Kikwik\JsonFormBundle\EventListener\JsonDocumentFormSubscriber;

class ProductFormType extends AbstractType
{
    public function __construct(private JsonDocumentFormSubscriber $jsonDocumentFormSubscriber)
    {
    }

    public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('name')
            ->add('techData',JsonDocumentCollectionType::class, [
                'model_labels' => [
                    'App\Model\Dimension' => 'Size of product',
                    'App\Model\TechData' => 'Technical data',
                ],
                'model_options' => [
                    'App\Model\Dimension' => ['unitOfMeasurement'=>'mm'],
                ]
            ])
            ->addEventSubscriber($this->jsonDocumentFormSubscriber)
        ;

        $builder->addEventListener(FormEvents::PRE_SET_DATA, [$this, 'onPreSetData']);
    }

    public function onPreSetData(PreSetDataEvent $event)
    {
        /** @var Product $product */
        $product = $event->getData();
        $form = $event->getForm();

        if(!$product || $product->getId() == null)
        {
            $form->add('techData',JsonDocumentCollectionType::class, [
                'model_labels' => [
                    'App\Model\Dimension' => 'Size of product',
                    'App\Model\TechData' => 'Technical data',
                ],
                'model_options' => [
                    'App\Model\Dimension' => ['unitOfMeasurement'=>'mm'],
                ],
                'data_models' => [
                    'App\Model\Dimension',
                    'App\Model\TechData'
                ]
            ]);
        }
    }

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

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~90 days

Total

5

Last Release

547d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bdd98919c8ee6645e854e72f8c6b76c503e12fd10078fb34ae1668cb2bd6d1a?d=identicon)[kikwik](/maintainers/kikwik)

---

Top Contributors

[![kikwik](https://avatars.githubusercontent.com/u/58590255?v=4)](https://github.com/kikwik "kikwik (11 commits)")

### Embed Badge

![Health badge](/badges/kikwik-json-form-bundle/health.svg)

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

###  Alternatives

[wallabag/wallabag

open source self hostable read-it-later web application

12.6k2.2k](/packages/wallabag-wallabag)[netgen/layouts-core

Netgen Layouts enables you to build and manage complex web pages in a simpler way and with less coding. This is the core of Netgen Layouts, its heart and soul.

3689.4k10](/packages/netgen-layouts-core)[jbtronics/settings-bundle

A symfony bundle to easily create typesafe, user-configurable settings for symfony applications

9546.7k2](/packages/jbtronics-settings-bundle)[pixelopen/cloudflare-turnstile-bundle

A simple package to help integrate Cloudflare Turnstile on Symfony.

31205.8k3](/packages/pixelopen-cloudflare-turnstile-bundle)[netgen/content-browser

Netgen Content Browser is a Symfony bundle that provides an interface which selects items from any kind of backend and returns the IDs of selected items back to the calling code.

14112.1k8](/packages/netgen-content-browser)[mapbender/mapbender

Mapbender library

10117.4k5](/packages/mapbender-mapbender)

PHPackages © 2026

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