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

FormMetadataBundle

by FlintLabs

Use annotations with the forms builder e.g. @Form\Field("text"). Associates metadata along with the entity class. Useful to make more generic controllers...

Form Metadata reader for Symfony2

Facilitates the basic configuration of form fields from metadata that is defined elsewhere, such as through annotations
in the entity or with an external yaml file (TODO). Allows for more generic handling of form types through controllers,
making them able to deal with dynamic entity/forms (such as for use with CMS sites).

See the form fields Annotations Reference

Note: People may want to consider the use of Symfony2 Abstract Forms to configure their forms external to the controller
as a best practice.

Annotations Example

Standard form builder

->add('dueDate', 'date', array('widget' => 'single_text'))

Using annotations in your entity

/**
 * @Form\Field("date", widget="single_text")
 */

Entity with some basic form annotations

use FlintLabs\Bundle\FormMetadataBundle\Configuration as Form;
use Symfony\Bundle\Validator\Constraints as Assert;

class Contact
{
    /**
     * @Form\Field("text")
     * @Assert\NotBlank()
     */
    public $name;

    /**
     * @Form\Field("textarea")
     */
    public $message;
}

Simple controller

class MyController
{
    public function contactAction()
    {
        $contact = new Contact();
        $form = $this->get('form_metadata.mapper')->createFormBuilder($contact)->getForm();

        if ($request->getMethod() == 'POST') {
            $form->bindRequest($request);

            if ($form->isValid()) {
                // perform some action, such as saving the task to the database
                return $this->redirect($this->generateUrl('task_success'));
            }
        }
    }
}

Installation

Update your deps file

[Form-Metadata]
    git=git@github.com:FlintLabs/Form-Metadata.git
    target=/bundles/FlintLabs/Bundle/FormMetadataBundle

Update your vendors

php bin/vendors update

Update your autoloader

// app/autoload.php
$loader->registerNamespaces(array(
    // ...
    'FlintLabs\\Bundle\\FormMetadataBundle' => __DIR__.'/../vendor/bundles/',
    // ...
));

Register the bundle references

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new FlintLabs\Bundle\FormMetadataBundle\FlintLabsFormMetadataBundle(),
        // ...
    );
}
Copyright (c) 2007-2011 Cameron Manderson

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
form_metadata:        []
  • Merge pull request #7 from mikeemoo/master
    By cammanderson, 8 years ago
  • AnnotationsDriver now continues up the entities inheritance chain if there is one
    By Mikee Franklin, 8 years ago
  • Removed specification of "type" field
    By cammanderson, 9 years ago
  • Fixed reference to type (removed)
    By cammanderson, 9 years ago
  • Moved the annotations reference to the WIKI
    By cammanderson, 9 years ago
  • Continued adding examples
    By cammanderson, 9 years ago
  • Continued updated documentation
    By cammanderson, 9 years ago
  • Updated some documentation examples
    By cammanderson, 9 years ago
  • Updated the documentation RE options for annotations
    By cammanderson, 9 years ago
  • Updated reference to the md
    By cammanderson, 9 years ago
  • moved the docs to the right location
    By cammanderson, 9 years ago
  • Updated the annotations
    By cammanderson, 9 years ago
  • Added link to the annotations link
    By cammanderson, 9 years ago
  • Updated headings
    By cammanderson, 9 years ago
  • Updated the basis of the annotations reference
    By cammanderson, 9 years ago
  • Added in some minor configuration options and TODO comments
    By cammanderson, 9 years ago
  • Updated commenting on configuration
    By cammanderson, 9 years ago
  • Updated comments
    By cammanderson, 9 years ago
  • Updated example to show how to use annotations
    By cammanderson, 9 years ago
  • Updated status warning
    By cammanderson, 9 years ago
  • Removed min_legnth example
    By cammanderson, 9 years ago
  • Added overloading of properties to example
    By cammanderson, 9 years ago
  • Updated the field configuration and annotations
    By cammanderson, 9 years ago
  • Updated the reference for mapping
    By cammanderson, 9 years ago
  • Updated references to driver
    By cammanderson, 9 years ago
  • Updated the naming for the drivers
    By cammanderson, 9 years ago
  • Updated the driver namespaces
    By cammanderson, 9 years ago
  • Updated the DI alias and references in services.xml
    By cammanderson, 9 years ago
  • Updated documentation headings
    By cammanderson, 9 years ago
  • Updated reference to reader
    By cammanderson, 9 years ago