Feature: #104168 - PSR-14 event for modifying countries
See forge#104168
Description
A new PSR-14 event
\TYPO3\
has been introduced to modify the list of countries provided by
\TYPO3\
.
This event allows to add, remove and alter countries from the list used by the
provider class itself and ViewHelpers like
<f:
.
Note
The DTO
\TYPO3\
uses EXT:
for translating
the country names.
If additional countries are added, add translations to countries.
via locallangXMLOverride.
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);
}
}
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']
['EXT:core/Resources/Private/Language/Iso/countries.xlf'][]
= '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>
Impact
Using the PSR-14 event
Before
allows
modification of countries provided by
Country
.