Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@Gregwar

Description

@Gregwar
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.