Giter VIP home page Giter VIP logo

formbundle's Introduction

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

formbundle's People

Contributors

adrienbrault avatar dkorsak avatar gregwar avatar koc avatar lmcd avatar lumbendil avatar nishigori avatar tobiassjosten avatar vhpoet avatar vjnrv avatar xwb avatar yosmanyga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

formbundle's Issues

'property' behaviour is different from 'core' entity type

Not a bug, but something I've been dealing with and like to discuss.

The 'property' option of the 'entity_id' type is currently a setting to use another property instead of the primary key. This is inconsistent with the implementation of the 'entity' type (thus confusing).

http://symfony.com/doc/current/reference/forms/types/entity.html#property
"This is the property that should be used for displaying the entities as text in the HTML element. If left blank, the entity object will be cast into a string and so must have a __toString() method."

Wouldn't it be better to let the 'property' option behave the same and use it when the type is rendered as text?

Rendering as text is also a bit weird, since you get to edit the primary key or other defined field. Maybe the types should even be changed to:

  • hidden
  • hidden + visible label containing the info derived from the 'property' option

3.0 compatibility

Hello
Is it compatible with 3.0 version of symfony ?
Thanks in advance.

Create tag

Hi!
Please create a tag for the branch where your bundle supports symfony 2.5.*.
Thanks.

Fatal error due to deprecation of Symfony\Component\Form\Util\PropertyPath

I have this fatal error after symfony vendor upgrade, trying to use "entity_id" :

FatalErrorException: Error: Class 'Symfony\Component\Form\Util\PropertyPath' not found in vendor/gregwar/form-bundle/Gregwar/FormBundle/DataTransformer/EntityToIdTransformer.php line 85

PropertyPath class is apparently deprecated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.