-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Automated label generation for forms #11456
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
Conversation
*/ | ||
public function buildView(FormView $view, FormInterface $form, array $options) | ||
{ | ||
if ($options['label'] === null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be null === $options['label']
(also in the expressions below).
@webmozart do you agree on the implementation? I'll work on documentation PRs as soon as the implementation is validated here |
See https://github.com/Elao/ElaoFormTranslationBundle if you don't know already it. |
@@ -177,6 +177,11 @@ private function registerFormConfiguration($config, ContainerBuilder $container, | |||
$config['form']['csrf_protection']['enabled'] = $config['csrf_protection']['enabled']; | |||
} | |||
|
|||
if (array_key_exists('auto_label', $config['form'])) { | |||
$loader->load('form_auto_label.xml'); | |||
$container->setParameter('form.type_extension.auto_label.auto_label', $config['form']['auto_label']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the parameter name looks weird with auto_label
being duplicated. form.type_extension.auto_label.format
might be better
Thanks for the idea and PR @alexandresalome! I had a little different solution in mind, which I uploaded in #12050. Please let me know whether this is convenient for you. Cheers! |
This PR was merged into the 2.6-dev branch. Discussion ---------- [Form] Added "label_format" option | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11456 | License | MIT | Doc PR | TODO This PR replaces #11456. It adds a "label_format" option which allows to configure a format for generating labels. Two placeholders are available: `%name%` and `%id%`. **Feedback wanted**: Should we change the placeholders to `{{ name }}` and `{{ id }}`? The option is inherited from the parent form if not set explicitly on a field: ```php $form = $this->createForm('myform', $data, array('label_format' => 'form.label.%id%')); ``` Follow-up PR: Make the default label format and translation domain configurable in config.yml. Commits ------- aad442d [Form] Added "label_format" option
Discussion started in #11298
This PR is about adding an option to automate the label generation for forms:
This option would be useful for big I18Ned applications with standardized label form translations. We could also add an option for a default translation_domain.
I started this work as a third-party extension, because most applications don't need it, so the footprint is null for them.
What is your advice on it?