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

[Form] Ability to define form theme file in type class #23070

Closed
bOmBeLq opened this Issue Jun 5, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@bOmBeLq

bOmBeLq commented Jun 5, 2017

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Symfony version 3.3.0

So I've been wondering what if we added a theme option to form type options. By default this field value would be null for BC but if value set then it would result in kind of automated call to
{% form_theme form_view theme_from_the_type_options %}

This would allow for simpler creation of bundles with form types which already have templates. Currently you would have to use compiler pass to automaticly add your theme to twig themes when bundle is registered or user has to manually register your form theme (I've seen both cases being used by bundle creators).

Having the theme option on form type would also allow for much simpler templating of forms.
For example you could have form type named JqueryUploadType
Now if you define separate template named jquery_upload_theme.html.twig
then you have to define there blocks named jquery_upload_widget, jquery_upload_row etc. and also register your theme in global themes list or manually call form_theme.

With the theme option on form having form_widget and form_row blocks would be enough because the template is applied only to this field. I know you can achive this by calling
{% form_theme form.yourField 'path_to_template.html.twig' %} but this requires some extra code if you use your field in many places. Also if you use it as CollectionType entry then you would have to iterate over all fields.

Is there any particular reason such option has not been introduced on form types yet?
Would this be an performance issue? Or maybe it's about separation of backend and frontend logic?

@iltar

This comment has been minimized.

Show comment
Hide comment
@iltar

iltar Jun 7, 2017

Contributor

Or maybe it's about separation of backend and frontend logic?

I think this is the primary reason. Things related to your view, should not be in a blueprint that maps html elements to data objects and validation.

Contributor

iltar commented Jun 7, 2017

Or maybe it's about separation of backend and frontend logic?

I think this is the primary reason. Things related to your view, should not be in a blueprint that maps html elements to data objects and validation.

@bOmBeLq

This comment has been minimized.

Show comment
Hide comment
@bOmBeLq

bOmBeLq Jun 7, 2017

@iltar Yes, though there are still some parts of form type that strongly affect frontend:

  • type name itself
  • label option
  • attr option
  • getBlockPrefix method
  • finishView

I think that adding template path in options for convinience wouldn't be bad idea.
I'm going to do it anyway. The question is should I do a PR or a separate bundle which would add this functionality (though separate bundle may be hard to achieve).

bOmBeLq commented Jun 7, 2017

@iltar Yes, though there are still some parts of form type that strongly affect frontend:

  • type name itself
  • label option
  • attr option
  • getBlockPrefix method
  • finishView

I think that adding template path in options for convinience wouldn't be bad idea.
I'm going to do it anyway. The question is should I do a PR or a separate bundle which would add this functionality (though separate bundle may be hard to achieve).

@iltar

This comment has been minimized.

Show comment
Hide comment
Contributor

iltar commented Jun 7, 2017

@bOmBeLq

This comment has been minimized.

Show comment
Hide comment
@bOmBeLq

bOmBeLq Jun 7, 2017

Thank you very much for advice. This will be probably way to go for the "option" part. The complicated part will be to internally addding the template as theme to the form type. I will most likely extend the twig extensions somehow. This rises question to me: what about different template engines (like raw php). I need to check this one.

bOmBeLq commented Jun 7, 2017

Thank you very much for advice. This will be probably way to go for the "option" part. The complicated part will be to internally addding the template as theme to the form type. I will most likely extend the twig extensions somehow. This rises question to me: what about different template engines (like raw php). I need to check this one.

@bOmBeLq

This comment has been minimized.

Show comment
Hide comment
@bOmBeLq

bOmBeLq Oct 9, 2017

Closing in favor of pull request #23990.

bOmBeLq commented Oct 9, 2017

Closing in favor of pull request #23990.

@bOmBeLq bOmBeLq closed this Oct 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment