Home > Net >  Where and How I can modify the money_pattern of a MoneyType under Symfony 6
Where and How I can modify the money_pattern of a MoneyType under Symfony 6

Time:10-30

I would like to understand where and how I can cleanly modify the money_pattern of a MoneyType under Symfony 6.

I tried in :

  • the twig.yaml
  • the configureOptions of the MoneyType
  • the parameters of the item (add function)

Impossible to apply the value : money_pattern => '{{ widget }} €'

Thanks in advance for your answers

CodePudding user response:

money_pattern is fetched within the MoneyType based on the currency (so, 'EUR'). However, it is also affected by the locale that is set.

In (my own) default 'en', it is set to € {{ widget }}, but after setting \Locale::setDefault('de_DE'); the placement becomes {{ widget }} €.

That pattern comes from the PHP Extension ext-intl (or the symfony/polyfill-intl-icu - but the polyfill only has support for the 'en' locale).

If the currency is set as false, then the widget does not have a sign around it, and can be overridden in the twig/form template widgets, potentially overriding the money_widget custom form template.

  • Related