Skip to content
This repository

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

Closed
Gregwar opened this Issue · 5 comments

2 participants

Grégoire Passault Marc Weistroff
Grégoire Passault

Hi,

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:

$comment->setArticle($current_viewing_article);
$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 : https://github.com/Gregwar/FormBundle

Marc Weistroff

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

Grégoire Passault

OK I will

Marc Weistroff

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

Grégoire Passault

How would I call this then ?
entity_id ?

Grégoire Passault Gregwar referenced this issue from a commit in Gregwar/symfony
Grégoire Passault Gregwar [Form] Added the entity_id type (#1946) 05a064a
Grégoire Passault

You can have a look at the PR 1951 now
#1951

Grégoire Passault Gregwar closed this
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.