Developed with love by KnpLabs Hire us for your project!
25

dynamic-form-bundle

by LinioIT

Generates symfony forms based on Yaml configuration files

Dynamic Form Bundle

Latest Stable Version
License
Build Status
Scrutinizer Code Quality

Generates symfony forms based on YAML configuration files

Getting Started

This plugin requires Symfony ^2.8|^3.0

The recommended way to install Linio Dynamic Form Bundle is through composer.

{
    "require": {
        "linio/dynamic-form-bundle": "~2.0"
    }
}

Tests

To run the test suite, you need install the dependencies via composer, then
run PHPUnit.

$ composer install
$ vendor/bin/phpunit

Usage

Add the bundle on registerBundles() at AppKernel.php

new Linio\DynamicFormBundle\DynamicFormBundle();

The service dynamic_form.factory will be available.

Create your form on the Configuration File. The YAML structure for the Form should follow the next structure:

+---dynamic_form
|   \--- Form Name
|       \---Field Name
|           \---Field Options
|           \---Field Transformer
|           \---Field Validators

The method createform() takes the form configuration named new_user from app/config/config.yml.

use Linio\DynamicFormBundle\DynamicFormAware;

class TestController
{
    use DynamicFormAware;

    public function testAction()
    {
        $form = $this->getDynamicFormFactory()->createForm('new_user');
        return $this->render(
          'WebBundle:Default:dynamicForms.html.twig',
          ['form' => $form->createView(),]
        );
    }
}

The method getJsonConfiguration() takes the configuration from app/config/config.yml. and returns a JSON with the Form Configuration.

Example

Here's an example of a form named new_user with a single field called first_name:

dynamic_form:
    new_user:
        first_name:
            enabled: true
            type: text
            options:
                type: password
                required: true
            transformers:
            validators:

Options

Field options are the same as symfony, refer to the documentation

Transformers

When using transformers write both the class where it is defined and the calls you need.

dynamic_form:
    new_user:
        birthday:
            enabled: true
            type: text
            transformer:
              class: 'Linio\Frontend\CustomerBundle\Form\DataTransformer\BirthdayTransformer'
              calls:
                  - [setUserFormat, ['d/m/Y']]
                  - [setInputFormat, ['Y-m-d']]

Validators

When using validators call each validator constraint and its parameters like shown down below.

dynamic_form:
    new_user:
        first_name:
            enabled: true
            type: text
            validation:
              'Symfony\Component\Validator\Constraints\True':
                  message: 'The token is invalid.'
              'Symfony\Component\Validator\Constraints\Length':
                  min: 2
                  max: 50
  • Added autoload-dev to composer.
    By , 2 years ago
  • Updated ruleset and applied php-cs-fixer fixes.
    By nesl247, 2 years ago
  • Update .travis.yml
    By web-flow, 2 years ago
  • Merge pull request #16 from LinioIT/feature/symfony-3.2
    By web-flow, 2 years ago
  • Updated .travis.yml for PHP 7.1.
    By nesl247, 2 years ago
  • Updated README for new release.
    By nesl247, 2 years ago
  • Moved files to src/ and tests/ directories.
    By nesl247, 2 years ago
  • Updated compatibility to Symfony 3.2.
    By nesl247, 2 years ago
  • Require PHP 7.1+ and Symfony 3.2+.
    By nesl247, 2 years ago
  • Merge pull request #11 from psren/enable-fields-by-default
    By web-flow, 2 years ago
  • Merge pull request #15 from LinioIT/feature/validator-builder
    By web-flow, 3 years ago
  • Added validator builder.
    By klaussilveira, 3 years ago
  • Merge pull request #14 from smmd/master
    By web-flow, 3 years ago
  • [ALICE-1062] Added test for creating form with help messages.
    By Sagrario Meneses, 3 years ago
  • [ALICE-1062] Added help message.
    By Sagrario Meneses, 3 years ago
  • Merge pull request #13 from LinioIT/aramonc-patch-1
    By nesl247, 3 years ago
  • Added quotes for compatibility with Symfony 2.8.
    By , 3 years ago
  • change default value
    By Patrick Heller, 4 years ago
  • Merge pull request #9 from xurumelous/master
    By nesl247, 4 years ago
  • Added the ability to attach event subscribers to forms.
    By , 4 years ago
  • Updated symfony version requirements.
    By fernandocarletti, 4 years ago
  • Merge pull request #7 from tavofuentes/support/default-value-number-field
    By nesl247, 4 years ago
  • Added `defaultValue` for `NumberField`.
    By , 4 years ago
  • Merge pull request #6 from LinioIT/add-support-to-php7
    By klaussilveira, 4 years ago
  • Changed php required version to support PHP 7.
    By fernandocarletti, 4 years ago
  • Added data providers for choice fields.
    By fernandocarletti, 4 years ago
  • Merge pull request #5 from tavofuentes/hotfix/aditional-formly-fields
    By klaussilveira, 4 years ago
  • Refactored validation messages as array.
    By IsraelLinioMx, 4 years ago
  • Added `has` validation and return default instance into `getFormlyField`.
    By IsraelLinioMx, 4 years ago
  • Added aditional formly fields.
    By IsraelLinioMx, 4 years ago