Skip to content

[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

Closed
wants to merge 4 commits into from
Closed

[Form] Automated label generation for forms #11456

wants to merge 4 commits into from

Conversation

alexandresalome
Copy link

Q A
Bug fix? [no]
New feature? [yes]
BC breaks? [no]
Deprecations? [no]
Tests pass? TBD
Fixed tickets Not a fix, but discussed in #11298
License MIT
Doc PR TBD
standard edition PR TBD

Discussion started in #11298

This PR is about adding an option to automate the label generation for forms:

# app/config/config.yml
framework:
    form:
        # auto_label: ~                      # enable the extension
        # auto_label: form.%%type%%.%%name%% # set the auto_label globally, but allow overriding per form

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.

    form:
        translation_domain: "form"

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?

  • Inherit auto-label from parent
  • Create the documentation PR
  • Create the standard edition PR

*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
if ($options['label'] === null) {
Copy link
Member

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).

@alexandresalome
Copy link
Author

@webmozart do you agree on the implementation? I'll work on documentation PRs as soon as the implementation is validated here

@webda2l
Copy link

webda2l commented Aug 11, 2014

See https://github.com/Elao/ElaoFormTranslationBundle if you don't know already it.
This is a nice implementation.

@@ -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']);
Copy link
Member

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

@webmozart
Copy link
Contributor

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!

@webmozart webmozart closed this Sep 26, 2014
webmozart added a commit that referenced this pull request Sep 30, 2014
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants