Elao / ElaoFormTranslationBundle

Provides a nice way of generating translation keys for form fields
44 stars 12 forks source link

Add an optional formater on form fields in key generation (Make field names undercored) #17

Closed bigfoot90 closed 6 years ago

bigfoot90 commented 9 years ago

Add an option to allow underscore-ize field names

bigfoot90 commented 9 years ago

@Tom32i ping

benji07 commented 9 years ago

@bigfoot90 may be you can create a pull request ? Instead of just asking for new feature

bigfoot90 commented 9 years ago

Sure, just want to be sure you want that feature

benji07 commented 9 years ago

why not, if we can disable it

Tom32i commented 9 years ago

Hey @bigfoot90 sorry for my silence :)

What exactly do you mean by "underscore-ize field names" ?

bigfoot90 commented 9 years ago

suppose you have $builder->add('myFieldName'); in form builder, the translation id will be form.my_form.children.my_field_name.label

Tom32i commented 9 years ago

Oh all right, that could prove useful.

I'm thinking of implementing it that way: For now the FormTreeNode gets its name from the field name: new FormTreeNode($view->vars['name'], ...). We could add a Transformer that process that value before passing it to the FormTreeNode (the Transformer could be just a closure).

See: https://github.com/Elao/ElaoFormTranslationBundle/blob/master/Builders/FormTreeBuilder.php#L75

All you would have to do then is to create your custom field name transformer (CamelCase to SnakeCase in your case).

bigfoot90 commented 9 years ago

@Tom32i I was thinking adding a paramiter in bundle configuration only, do you have need to set the label transformer for each field?

benji07 commented 6 years ago

Spring cleaning, If this issue is still relevant, please reopen-it.