getCountries
Details
This page shows version 4.x. The current version can be found here.
The getCountries hook allows to modify the system’s list of countries.
Note
Using the getCountries hook has been deprecated and will no longer work in Contao 5.0. Decorate the Contao\CoreBundle\Intl\Countries
service instead.
Parameters
array
$translatedCountriesThe array containing the countries as filled by
\Contao\System::getCountries()according to the system’s configuration. This parameter has to be passed by reference if you want your changes to become effective.array
$allCountriesThe list of countries from the system config file
countries.php.
Example
// src/EventListener/GetCountriesListener.php
namespace App\EventListener;
use Contao\CoreBundle\DependencyInjection\Attribute\AsHook;
#[AsHook('getCountries')]
class GetCountriesListener
{
public function __invoke(array &$translatedCountries, array $allCountries): void
{
// Codes for the european countries
$europeanCountryCodes = ['de', 'at', 'ch' /*, … */];
// Remove all non-european countries
$translatedCountries = array_intersect_key($translatedCountries, array_flip($europeanCountryCodes));
}
}