8000 Rendering Forms without Translators and Validators · Issue #31968 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Rendering Forms without Translators and Validators #31968

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

Closed
PF4Public opened this issue Jun 9, 2019 · 7 comments
Closed

Rendering Forms without Translators and Validators #31968

PF4Public opened this issue Jun 9, 2019 · 7 comments

Comments

@PF4Public
Copy link
Contributor

Symfony version(s) affected: 4.3.1

Description
When a form is to be rendered, the following code in Twig runs:

{%- if translation_domain is same as(false) -%}               
{{- label -}}            
{%- else -%}
{{- label|trans(label_translation_parameters, translation_domain) -}}

By default translation_domain from validation "is not same as(false) ", which results in calling trans. Which in turn gives an exception

An exception has been thrown during the rendering of a template ("You cannot use the "Symfony\Bridge\Twig\Extension\TranslationExtension" if the Translation Contracts are not available. Try running "composer require symfony/translation".").

Trying to override translation_domain from validation implicitly enables validation and gives another error:

Validation support cannot be enabled as the Validator component is not installed. Try running "composer require symfony/validator".

How to reproduce
Try to render a Form without Translators and Validators

Possible Solution
translation_domain should be false if validation is disabled

@dFayet
Copy link
dFayet commented Jun 10, 2019

I'm not sure to have fully understood the validation part, for me if you pass some config to validation Symfony is right to ask you to install the Validator component.

Beside that I think that setting the translation_domain to false in the Form component if there is no translator installed would be correct. I doubt we want the form component to require symfony/translation

Any thoughts? @javiereguiluz

@javiereguiluz
Copy link
Member

The Form component doesn't require Translation at the moment (https://github.com/symfony/symfony/blob/4.4/src/Symfony/Component/Form/composer.json) and recently we also decoupled the Validator component from Translation (#28210).

@stof
Copy link
Member
stof commented Jun 10, 2019

but the Twig form theme needs at least the translation contracts to be installed.

@nicolas-grekas
Copy link
Member

I missed that. Then we should add translation-contracts to require, right?

@PF4Public
Copy link
Contributor Author
PF4Public commented Jun 10, 2019

@dFayet It is absolutely fine to require translation when trans function is used. It is absolutely fine to require validation, when it is used. But at present, I'm willing to use neither. And it worked fine until 4.3.1. It probably broke after 4.3

Having translation_domain set to validators under validation when validation itself isn't used makes twig require translations. Trying to set translation_domain to false implicitly enables validation.

In the end, because of this default setting translation_domain: validators, it is a deadlock: either translation should be enabled, or validation. I am however planning to use neither of them.

@nicolas-grekas IMHO, it would be better to fix default setting for translation_domain under validation, when validation is disabled.

@xabbuh
Copy link
Member
xabbuh commented Jun 11, 2019

@PF4Public Can you confirm that #31988 fixes this?

@fabpot fabpot closed this as completed Jun 11, 2019
fabpot added a commit that referenced this issue Jun 11, 2019
…ut translations (xabbuh)

This PR was merged into the 4.3 branch.

Discussion
----------

[TwigBridge] add back possibility to use form themes without translations

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31968
| License       | MIT
| Doc PR        |

Commits
-------

87c1d19 add back possibility to use form themes without translations
@PF4Public
Copy link
Contributor Author

Adding symfony/translation-contracts actually solves the issue.

Could anyone, please, explain what are the symfony/translation-contracts? Adding them did not actually pull in translation module. Is it some kind of a placeholder then?

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

No branches or pull requests

8 participants
0