Symfony 2:在表单构建器中使用Twig扩展

I need to change the way a value or label is formatted with a custom filter. However, I need to do this from the form builder rather than in the twig template itself. In other words, when I build my form in the abstract type class, I need to be able to apply specific formatting.

Here is one application where this is needed:

Labels assigned to form elements are based on the database table field names. I need to be able to change how those labels are rendered, such as title case, or upper case, etc.

What's the best way of doing this?

Thanks!

You can create a custom form field type, that extend from choice or entity field type. Then you can customize the template for the field applying filters or whatever you want.