By default, the Currencies class from the Intl component and the CurrencyType field from the Form component display all currencies defined in the ISO 4217 standard.
This list includes legacy currencies such as the German Mark or the Irish Pound, which were replaced by the Euro decades ago. For e-commerce or billing applications, showing obsolete currencies makes no sense and creates a poor user experience.
Symfony 7.4 solves this by filtering out legacy currencies by default and introducing new methods to check and filter currencies based on their legal tender status and validity dates.
New Intl Helpers
The Currencies class now includes methods to filter currencies by country
and date, using ICU metadata to determine their legal tender status and
validity period:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
use Symfony\Component\Intl\Currencies;
// get all today's legal and active currencies for a given country
$currencies = Currencies::forCountry('FR');
// Result: ['EUR']
// get all valid currencies for a given country at a specific date
$currencies = Currencies::forCountry(
    'ES',
    legalTender: null,
    active: true,
    date: new \DateTimeImmutable('1982-01-01')
);
// Result: ['ESP', 'ESB']
// validate if a currency is valid for a given country
$isValid = Currencies::isValidInCountry('CH', 'CHF');
// Result: trueNew Form Type Options
The CurrencyType form field now includes three new options to filter the
displayed currencies:
- legal_tender: (default:- truein 7.4 and- nullin previous versions) Controls whether to show only legal tender currencies (- true), only non-legal-tender currencies (- false), or all currencies (- null).
- active_at: Shows only currencies that were active (in circulation) at a specific date.
- not_active_at: Shows only currencies that were inactive (no longer in circulation) at a specific date.
These options help you build currency selectors that only show relevant choices to your users:
1 2 3 4
$builder->add('currency', CurrencyType::class, [
    'legal_tender' => null,
    'active_at' => new \DateTimeImmutable('2007-01-15', new \DateTimeZone('Etc/UTC')),
]); 
                
Interesting feature!