idci/extra-form-bundle

Symfony bundle that expand existing FormType feature to allow a dynamic form generation

Installs: 64 966

Dependents: 1

Suggesters: 1

Security: 0

Stars: 5

Watchers: 12

Forks: 1

Open Issues: 1

Type:symfony-bundle

v6.0.0 2022-11-25 18:07 UTC

README

ExtraFormBundle is a Symfony bundle that expand existing FormType features to allow dynamic forms generation.

This bundle provide:

  • A builder to generate forms from a configuration array. This allow you to configure your forms in any format convertible in an array (yaml, json, etc) and dynamically generate your forms.
  • A set of extra types (iban, captcha..) ready to use.
  • An api that exposes all symfony form types as 'extra form types'
  • An api that exposes all symfony validation constraints as 'extra form constraints'

SensioLabsInsight Build

Installation

Install this bundle using composer:

$ php composer require idci/extra-form-bundle:dev-master

Import the bundle configuration:

# app/config/config.yml

imports:
    - { resource: '@IDCIExtraFormBundle/Resources/config/config.yml' }

That's it, you are ready to use the extra form builder.

Use the editor

If you need the api or the editor:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new FOS\RestBundle\FOSRestBundle(),
        new JMS\SerializerBundle\JMSSerializerBundle(),
    );
}

Enable the serializer:

# app/config/config.yml

fos_rest:
    param_fetcher_listener: true # if you want to add configured types
    service:
        serializer: jms_serializer.serializer

Import the routes:

# app/config/routing.yml
extra_form:
    resource: "@IDCIExtraFormBundle/Controller/"
    type: annotation

Install the assets:

php bin/console assets:install --symlink

The editor requires bootstrap and jquery. If you don't use it already in your project, just add the following lines in your views.

{% block javascripts %}
    {{ parent() }}
    <script type="text/javascript" src="{{ asset('bundles/idciextraform/js/vendor/jquery-2.2.4.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('bundles/idciextraform/js/vendor/bootstrap.min.js') }}"></script>
{% endblock %}

{% block stylesheets %}
    {{ parent() }}
    <link rel="stylesheet" type="text/css" href="{{ asset('bundles/idciextraform/css/bootstrap.min.css') }}" />
    <link rel="stylesheet" type="text/css" href="{{ asset('bundles/idciextraform/css/bootstrap-theme.min.css') }}" />
{% endlbock %}

Use the configured types

You can register configured types via the editor. It allows you to access types with pre-configured fields.

Register doctrine bundle in your application kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
    );
}

Then update the doctrine schema. It will create a table to register the configured types in database.

doctrine:schema:update --force

Documentation

Going further

Tests

We use docker and docker-compose to run the tests, along with a Makefile.

Install the bundle dev dependencies:

$ make composer-update

To execute unit tests:

$ make phpunit