Feature: #104168 - PSR-14 event for modifying countries

See forge#104168

Description

A new PSR-14 event \TYPO3\CMS\Core\Country\Event\BeforeCountriesEvaluatedEvent has been introduced to modify the list of countries provided by \TYPO3\CMS\Core\Country\CountryProvider .

This event allows to add, remove and alter countries from the list used by the provider class itself and ViewHelpers like <f:form.countrySelect />.

Example

An example corresponding event listener class:

<?php
declare(strict_types=1);

namespace MyVendor\MyExtension\EventListener;

use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Country\Country;
use TYPO3\CMS\Core\Country\Event\BeforeCountriesEvaluatedEvent;

final readonly class EventListener
{
    #[AsEventListener(identifier: 'my-extension/before-countries-evaluated')]
    public function __invoke(BeforeCountriesEvaluatedEvent $event): void
    {
        $countries = $event->getCountries();
        unset($countries['BS']);
        $countries['XX'] = new Country(
            'XX',
            'XYZ',
            'Magic Kingdom',
            '987',
            '🔮',
            'Kingdom of Magic and Wonders'
        );
        $event->setCountries($countries);
    }
}
Copied!
EXT:my_extension/ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']
    ['EXT:core/Resources/Private/Language/Iso/countries.xlf'][]
        = 'EXT:my_extension/Resources/Private/Language/countries.xlf';
Copied!
EXT:my_extension/Resources/Private/Language/countries.xlf
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
    <file source-language="en" datatype="plaintext" date="2024-01-08T18:44:59Z" product-name="my_extension">
        <body>
            <trans-unit id="XX.name" approved="yes">
                <source>Magic Kingdom</source>
            </trans-unit>
            <trans-unit id="XX.official_name" approved="yes">
                <source>Kingdom of Magic and Wonders</source>
            </trans-unit>
        </body>
    </file>
</xliff>
Copied!

Impact

Using the PSR-14 event BeforeCountriesEvaluatedEvent allows modification of countries provided by CountryProvider .