Provides the "entity_id" type (read "entity identifier")
Branch: master
Clone or download
Gregwar Merge pull request #42 from kingchills/master
Adding support to allow usage in Symfony 4
Latest commit b84c52f Jul 13, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
DataTransformer Fix fatal error in data dransformer (unknown exception class) May 3, 2017
DependencyInjection Changed directory structure to comply with Symfony CS Aug 12, 2011
Resources/config Update services.yml Jun 2, 2016
Tests * Updated composer for symfony 4.* Jul 11, 2018
Type Merge pull request #38 from XWB/formtype May 12, 2016
.gitignore
GregwarFormBundle.php Changed directory structure to comply with Symfony CS Aug 12, 2011
LICENSE Moved license and readme on the root Aug 5, 2011
README.md * Updated readme to show proper form instantiation Jul 11, 2018
composer.json * Updated composer for symfony 4.* Jul 11, 2018
phpunit.xml.dist * Updated composer for symfony 4.* Jul 11, 2018

README.md

Gregwar's FormBundle

paypal

GregwarFormBundle provides the form type "entity_id"

Installation

To install GregwarFormBundle, run composer require gregwar/form-bundle.

Then, register the bundle in the application kernel :

<?php
// app/AppKernel.php
//...
public function registerBundles()
{
    $bundles = array(
        ...
        new Gregwar\FormBundle\GregwarFormBundle(),
        ...
    );
...

Finally, add the following block to the configuration :

# app/config/config.yml
gregwar_form: ~

Usage

The entity_id is a field that contains an entity id, this assumes you set up javascripts or any UI logics to fill it programmatically.

The usage look like the entity field type one, except that the query builder have to returns one unique result. One full example :

<?php
//...
$builder
    ->add('city', EntityIdType::class, array(
        'class' => 'Project\Entity\City',
        'query_builder' => function(EntityRepository $repo, $id) {
            return $repo->createQueryBuilder('c')
                ->where('c.id = :id AND c.available = 1')
                ->setParameter('id', $id);
        }
    ))
    ;

Note that if you don't provide any query builder, ->find($id) will be used.

You can also chose to show the field, by passing the hidden option to false:

<?php
//...
$builder
    ->add('city', EntityIdType::class, array(
        'class' => 'Project\Entity\City',
        'hidden' => false,
        'label' => 'Enter the City id'
    ))
    ;

Using the property option, you can also use another identifier than the primary key:

<?php
//...
$builder
    ->add('recipient', EntityIdType::class, array(
        'class' => 'Project\Entity\User',
        'hidden' => false,
        'property' => 'login',
        'label' => 'Recipient login'
    ))
    ;

Notes

There is maybe bugs in this implementations, this package is just an idea of a form field type which can be very useful for the Symfony2 project.

License

This bundle is under MIT license