-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Description
This is an idea of improvement for the Form feature: allow passing parameters to the translated fields
In SF, the translation feature is available almost everywhere:
- The Controllers ( Fully available )
- The Twig ( Fully available )
- The Services ( Fully available )
- The Forms ( Partially available )
The translation feature is partially available in the SF Forms because we cannot translate the keys which are expecting parameters to be translated.
If the translation parameters would be available directly in the Form Classes,
the SF developers would have theses gains :
- Be able to create SF Forms Fully Dynamic
- Avoid duplicating some keys specific to the forms
Currently in the Twig templates there are two ways to display a SF Form :
1 - Integrate the fields manually One by One
2 - Integrate the fields dynamically by looping over each field of the form
I am using the second Method for the following reasons:
It is time consuming to integrate all the fields of a form manually ( one by one ) in twig template.
It is also time consuming to maintain a form if we have to touch two different layers (Twig+ Form Class) for each modification.
Example
-> This is French translation file : App.fr.yml
views:
index:
created_at: crée le %date%
-> This is my English Translation file : App.en.yml
views:
index:
created_at: created at %date%
-> This is my Form
...
->add('created', DateTimeType::class,
array('label' => 'views.index.created_at',
'widget' => 'single_text',
'input' => 'datetime',
'format' => 'dd/MM/yyyy HH:mm',
'attr' => array('data-date-format' => 'DD-MM-YYYY HH:mm'),
'translation_domain' => 'App'));
...
-> This is my Twig template :
{% for key, field in form.children %}
<div class="form-group form-md-line-input form-md-floating-label" id="block_{{ key }}">
{{form_label(field)}}
{{form_errors(field)}}
{{form_widget(field)}}
</div>
{% endfor %}