BeforeCountriesEvaluatedEvent¶
New in version 13.3
The PSR-14 event \TYPO3\
allows to modify the list of countries provided by
the \TYPO3\
.
This event allows to to add, remove and alter countries from the list used by the provider class itself and ViewHelpers like the Form.countrySelect ViewHelper <f:form.countrySelect>.
Note
The DTO \TYPO3\
uses EXT:
for translating
the country names.
If additional countries are added, add translations to countries.
via locallangXMLOverride.
Table of contents
Example: Add a new country to the country selectors¶
The following event listener adds a new country, 'Magic Kingdom' with alpha 2 code 'XX' and alpha 3 code 'XXX'.
<?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);
}
}
New in version 13.0
The PHP attribute \TYPO3\
has been
introduced to tag a PHP class as an event listener. Alternatively, or if you
need to be compatible with older TYPO3 versions, you can also register an
event listener via the Configuration/
file. Switch to
an older version of this page for an example or have a look at the section
Implementing an event listener in your extension.
As the localized names for the countries are defined in file
EXT:
, this language
file needs to be extended via
locallangXMLOverride:
<?php
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locallangXMLOverride']
['EXT:core/Resources/Private/Language/Iso/countries.xlf'][]
= 'EXT:my_extension/Resources/Private/Language/countries.xlf';
You can now override the language file in the path defined above:
<?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" resname="XX.name" approved="yes">
<source>Magic Kingdom</source>
</trans-unit>
<trans-unit id="XX.official_name" resname="XX.official_name" approved="yes">
<source>Kingdom of Magic and Wonders</source>
</trans-unit>
</body>
</file>
</xliff>
And add additional translations for German:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="de" datatype="plaintext" date="2024-01-08T18:44:59Z" product-name="my_extension">
<body>
<trans-unit id="XX.name" resname="XX.name" approved="yes">
<source>Magic Kingdom</source>
<target>Magisches Königreich</target>
</trans-unit>
<trans-unit id="XX.official_name" resname="XX.official_name" approved="yes">
<source>Kingdom of Magic and Wonders</source>
<target>Königreich der Magie und Wunder</target>
</trans-unit>
</body>
</file>
</xliff>
And Klingon:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" target-language="tlh" datatype="plaintext" date="2024-01-08T18:44:59Z" product-name="my_extension">
<body>
<trans-unit id="XX.name" resname="XX.name" approved="yes">
<source>Magic Kingdom</source>
<target>‘oHtaHghach wo’</target>
</trans-unit>
<trans-unit id="XX.official_name" resname="XX.official_name" approved="yes">
<source>Kingdom of Magic and Wonders</source>
<target>‘oHtaHghach je Dojmey wo’</target>
</trans-unit>
</body>
</file>
</xliff>