Skip to content

[Form] Idea about a new type: hidden_entity #1946

Gregwar opened this Issue Aug 12, 2011 · 5 comments

2 participants

Gregwar commented Aug 12, 2011


I thought about a new type of field type which can solve several problems i met on the user group.

The idea is to create an "hidden_entity" type which is just an hidden id in the form, and an entity fetched in the database by the DataTransformer. Here are two example of use:

The transport entity case

Imagine you have a comment which should be attached to an article. In the page, you'll maybe have your form posting to a special URL like /addComment/{article_id}, and then fetch back the article from the URL.

With hidden_entity, this would be way simplied since you'd just have to put the following on your comment form:

$builder->add('article', 'hidden_entity');

And populate if from the controller when rendering the form:

$form = $this->createForm(new CommentType(), $comment);

The "JS-UI" case

Just imagine you want your user to select something among a very large set of data, like a city, and use some complex JavaScript UI like autocompletion, dynamic map etc. The current symfony's entity will generate a containing the whole entries from the database, which is not acceptable in this case. Using hidden_entity, you can easily add an hidden id to your form and your free to do whatever you want to fill it. Hoping for feedbacks about this idea, I already wrote a prototype of this :

marcw commented Aug 12, 2011

Yes, I think we need this. Working with entities & hidden fields is currently a pain. Could you please make a pull request ?

Gregwar commented Aug 12, 2011

OK I will

marcw commented Aug 12, 2011

btw, I don't think we only want an hidden field. I'm currently having the case where a input="text" is the thing I really need. Thus, I think you'll need to provide an option to handle that

Gregwar commented Aug 12, 2011

How would I call this then ?
entity_id ?

@Gregwar Gregwar added a commit to Gregwar/symfony that referenced this issue Aug 12, 2011
@Gregwar Gregwar [Form] Added the entity_id type (#1946) 05a064a
Gregwar commented Aug 12, 2011

You can have a look at the PR 1951 now

@Gregwar Gregwar closed this Aug 12, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.