diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f0a0b73..088f9b4 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -25,6 +25,9 @@ public function getConfigTreeBuilder() ->integerNode('scale') ->defaultValue(2) ->end() + ->scalarNode('default_currency') + ->defaultValue('EUR') + ->end() ->arrayNode('currencies') ->scalarPrototype()->end() ->defaultValue(['EUR']) diff --git a/Form/MoneyType.php b/Form/MoneyType.php index 141cef7..410f1a3 100644 --- a/Form/MoneyType.php +++ b/Form/MoneyType.php @@ -14,10 +14,12 @@ class MoneyType extends AbstractType { private $moneyHelper; + private $config; - public function __construct(MoneyHelper $moneyHelper) + public function __construct(MoneyHelper $moneyHelper, array $config) { $this->moneyHelper = $moneyHelper; + $this->config = $config; } /** @@ -60,7 +62,7 @@ public function configureOptions(OptionsResolver $resolver) 'amount_options' => [ 'label' => false, ], - 'default_currency_code' => 'EUR', + 'default_currency_code' => $this->config['default_currency'], 'currency_enabled' => false, 'currency_type' => CurrencyType::class, 'currency_options' => [ diff --git a/Resources/config/services.yaml b/Resources/config/services.yaml index f36f2d5..008c922 100644 --- a/Resources/config/services.yaml +++ b/Resources/config/services.yaml @@ -23,9 +23,12 @@ services: Padam87\MoneyBundle\Service\MoneyHelper: public: true arguments: - - '%padam87_money.config%' + $config: '%padam87_money.config%' + + Padam87\MoneyBundle\Form\MoneyType: + arguments: + $config: '%padam87_money.config%' - Padam87\MoneyBundle\Form\MoneyType: ~ Padam87\MoneyBundle\Form\CurrencyType: arguments: - - '%padam87_money.config%' + $config: '%padam87_money.config%'