Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formtypes should be placed in Form\Type-Directory #5695

Closed
wants to merge 3 commits into from

Conversation

HKandulla
Copy link

No description provided.

@zatikbalazs
Copy link
Contributor

Yes, according to the Symfony Book you should put them in the \Form\Type directory.

@xabbuh
Copy link
Member

xabbuh commented Sep 23, 2015

👍 Though we have two use statements on the same page. Can you please update them too?

@HKandulla
Copy link
Author

@xabbuh: I am not sure what two use statements you mean. Can you give me the lines?

@xabbuh
Copy link
Member

xabbuh commented Sep 24, 2015

@HKandulla Sorry, I missed the fact that you already tackled them.

@xabbuh
Copy link
Member

xabbuh commented Sep 27, 2015

@HKandulla Can you also add the filename comments like started in #5727?

Included hint about file location for Controller- and View-Files.
@HKandulla
Copy link
Author

@xabbuh: Good idea. I added the filename comments to all files (Formtype, Controller and Views). Additionally I changed the namespace for the example Controller from "AppBundle\Controller\Admin" to "AppBundle\Controller" to use standard directory order.

@@ -51,7 +52,8 @@ form in its own PHP class::

To use the class, use ``createForm`` and instantiate the new class::

use AppBundle\Form\PostType;
// src/AppBundle/Controller/PostController.php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this here (it does not really matter how your controller is named and we actually omit most of the class already for readability). Though I would now move the use statement below the placeholder comment.

@wouterj
Copy link
Member

wouterj commented Oct 9, 2015

I'm not sure I'm 100% behind this PR. A major goal of the best practices guide is to make everything simpler and quicker to write. That's why templates have been moved to /app/Resources (AppBundle:static:home.html.twig vs static/home.html.twig).

For the same reason, I would argue that the Type prefix of the form type classes already makes it obvious that these are types. Adding a deeper level of namespaces, Type, means we only add more characters to write.

On the other side, things can get out of hand pretty quickly when having a form type, extension and listener. It's also consistent with the internal Form component extension organization.

So I'm leaning a bit towards -0.4 for using Form\Type in the best practices (but instead, updating to the book to use Form directly). I would also like to see the opinions of @weaverryan @javiereguiluz before merging/not-merging this.

Anyway, as always a huge thanks to you for putting time into making the Symfony documentation more consistent! It's great you noticed this inconsistency, it's just a matter of deciding the practice.

@javiereguiluz
Copy link
Member

@wouterj here it is the discussion I had with @weaverryan about this issue: symfony/demo#6

@HKandulla
Copy link
Author

Personally, I like to keep FormTypes in an own directory, especially when you start to put more/all busines logik into one Bundle. But I leave it up to you. Let me know, than I can do the changes xabbuh pointed out before you merge.

@weaverryan
Copy link
Member

The Symfony best practices are to put them in the Form directory alone. As @HKandulla hinted, this is totally subjective. I dislike the idea of making a beginner create this AppBundle/Form/Type/* structure - where Form will have nothing in it (other than a Type directory) for many projects. For the Symfony Demo - which is maturing into a larger project - having Form\Type makes more sense, but you could still put all the "types" in Form and other things in sub-directories (Form/DataTransformer).

My vote is to keep it in Form.

@wouterj
Copy link
Member

wouterj commented Dec 21, 2015

As there seems to be a general vote to not place form types in Form\Type by default, I'm going to close this PR. You can of course still comment if you disagree with this decision.

In order to make things more clear and explicitly tell people that this is not a hard rule (nothing in the docs is btw), I've created a new PR adding a best practice box for the form type namespace: #6059

🎄

@wouterj wouterj closed this Dec 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants