Skip to content

Commit

Permalink
Support for default currency config
Browse files Browse the repository at this point in the history
  • Loading branch information
Padam87 committed May 1, 2020
1 parent bcf178d commit 574825e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public function getConfigTreeBuilder()
->integerNode('scale')
->defaultValue(2)
->end()
->scalarNode('default_currency')
->defaultValue('EUR')
->end()
->arrayNode('currencies')
->scalarPrototype()->end()
->defaultValue(['EUR'])
Expand Down
6 changes: 4 additions & 2 deletions Form/MoneyType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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' => [
Expand Down
9 changes: 6 additions & 3 deletions Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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%'

0 comments on commit 574825e

Please sign in to comment.