Override country list in 5.7

Is there an easy way to override the system country list to exclude extra countries and survive a core upgrade?

Located at src/Localization/Service/CountryList.php


View Replies:
JohntheFish replied on at Permalink Reply
For 5.6 I built a Country/State manager addon to allow the list to be managed from the dashboard.https://www.concrete5.org/marketplace/addons/country-state-manager/... I find it pretty cool, but it didn't attract much of a marketplace following, so isn't high on my long list of addons to port to 5.7.
daenu replied on at Permalink Reply
Copy the

Adapt the namespace from
namespace Concrete\Core\Localization\Service;

namespace Application\Core\Localization\Service;

You're now free to add/remove methods to that class without having any risks when updating the site.
alexwag replied on at Permalink Reply
Thanks Daenu, I tried that but it seems I may be looking in the wrong place.

For example, I have tried remove two countries by unsetting them in loadCountries() in both the core and application version.

To remove Andorra & Antarctica, I've done the following..

$countries = \Punic\Territory::getCountries();
            // Fake countries
            $countries['IM'], // Isle of Man (it's a British Crown Dependency)
            $countries['JE'], // Jersey (it's a British Crown Dependency)
            $countries['AD'], // Andorra
            $countries['AQ']  // Antarctica

.. yet they are still present in any country list in the system.
daenu replied on at Permalink Reply
After digging a bit I found that the system parses the /concrete/languages & /application/languages folders to create that array. So or you delete the corresponding folder (?) or you override the Localization Class (/concrete/src/Localization/Localization.php). There is a method called "getAvailableInterfaceLanguages". So I defined an exclude array to check with in_array:
// ...
$excluded = array(
if (file_exists(DIR_LANGUAGES)) {
    $contents = $fh->getDirectoryContents(DIR_LANGUAGES);
    foreach ($contents as $con) {
        if (is_dir(DIR_LANGUAGES . '/' . $con) && file_exists(DIR_LANGUAGES . '/' . $con . '/LC_MESSAGES/messages.mo')) {
            if(!in_array($con, $excluded)){
                $languages[] = $con;
alexwag replied on at Permalink Reply
hmm, that seems more related to languages.

I have discovered that making changes to..


.. by unsetting array values in loadCountries() seems to works.

But obviously this won't survive a c5 upgrade.

It seems this cannot be overridden by copying into /application/src.
katalysis replied on at Permalink Reply
Did anyone ever find a way to override src/Localization/Service/CountryList.php safely?

I need to add Jersey, Guernsey and Isle of Man (all British Crown dependencies) to the list for a Community Store site.
Qodo replied on at Permalink Reply
This can be done by overriding the event:

Events List:

Hooking into events:

The easiest thing to do is add override code to
. You can either replace list of countries with something like this:

Events::addListener('on_get_countries_list', function($event) {
    // Create our list of countries
    $event['countries'] = array(
        'GB' => 'United Kingdom',
    return $event;

Or remove the countries you don't want like this:

Events::addListener('on_get_countries_list', function($event) {
    // Remove United Kingdom
    return $event;