1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Exchange Rate Bundle, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2017 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace RunOpenCode\Bundle\ExchangeRate\Form\Type; |
11
|
|
|
|
12
|
|
|
use RunOpenCode\ExchangeRate\Configuration; |
13
|
|
|
use RunOpenCode\ExchangeRate\Contract\RatesConfigurationRegistryInterface; |
14
|
|
|
use Symfony\Component\Form\AbstractType; |
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
16
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class CurrencyType |
20
|
|
|
* |
21
|
|
|
* Currency choice type. |
22
|
|
|
* |
23
|
|
|
* @package RunOpenCode\Bundle\ExchangeRate\Form\Type |
24
|
|
|
*/ |
25
|
|
|
class CurrencyCodeType extends AbstractType |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
protected $defaults; |
31
|
|
|
|
32
|
2 |
|
public function __construct(RatesConfigurationRegistryInterface $registry, $baseCurrencyCode, array $defaults = []) |
33
|
|
|
{ |
34
|
2 |
|
$currencyCodes = []; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Configuration $configuration |
38
|
|
|
*/ |
39
|
2 |
|
foreach ($registry as $configuration) { |
40
|
2 |
|
$currencyCode = $configuration->getCurrencyCode(); |
41
|
2 |
|
$currencyCodes[$currencyCode] = $currencyCode; |
42
|
|
|
} |
43
|
|
|
|
44
|
2 |
|
asort($currencyCodes); |
45
|
|
|
|
46
|
2 |
|
$currencyCodes = array_merge([$baseCurrencyCode => $baseCurrencyCode], $currencyCodes); |
47
|
|
|
|
48
|
2 |
|
$this->defaults = array_merge(array( |
49
|
2 |
|
'choice_translation_domain' => false, |
50
|
2 |
|
'choices' => $currencyCodes |
51
|
2 |
|
), $defaults); |
52
|
2 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
*/ |
57
|
1 |
|
public function configureOptions(OptionsResolver $resolver) |
58
|
|
|
{ |
59
|
|
|
$resolver |
60
|
1 |
|
->setDefaults($this->defaults); |
61
|
1 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
1 |
|
public function getParent() |
67
|
|
|
{ |
68
|
1 |
|
return ChoiceType::class; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|