PHPackages                             gertvdb/iso3166 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. gertvdb/iso3166

ActiveDrupal-module[Utility &amp; Helpers](/categories/utility)

gertvdb/iso3166
===============

Provide country and continent plugins based on ISO3611 data

8.1.1(5y ago)042[4 PRs](https://github.com/gertvdb/iso3166/pulls)GPL-2.0-or-laterPHP

Since Feb 16Pushed 3y ago1 watchersCompare

[ Source](https://github.com/gertvdb/iso3166)[ Packagist](https://packagist.org/packages/gertvdb/iso3166)[ RSS](/packages/gertvdb-iso3166/feed)WikiDiscussions 8.x-1.x Synced today

READMEChangelog (2)Dependencies (7)Versions (7)Used By (0)

[![Build Status](https://camo.githubusercontent.com/d0b48fa8ba93aa55ecbafd4eaf480ef23670526a102f6b603bbf4c29b687e8fd/68747470733a2f2f7472617669732d63692e6f72672f676572747664622f69736f333136362e7376673f6272616e63683d382e782d312e78)](https://travis-ci.org/gertvdb/iso3166)

Description
-----------

[](#description)

This module provides countries and contintents based on the official iso3166 data. It provides both countries and continents as plugins and maps them together. Since the countries and continents are plugin the end user can easily add it's own or override the existing.

Installation
------------

[](#installation)

To install this module, do the following:

With composer:

1. `composer require gertvdb/iso3166`

Examples
--------

[](#examples)

You can find an example on how to use the iso3166 module below. The module provides a service to work with the plugin data.

#### Using the plugin managers.

[](#using-the-plugin-managers)

The plugin managers provide some extra methods to easily get country and continent data.

```
  /** @var \Drupal\iso3166\Plugin\CountryManager $pluginManager */
  $pluginManager = \Drupal::service('plugin.manager.country');

  $belguim = $pluginManager->getCountry('BE');
  $allCountries = $pluginManager->getCountries();

```

```
  /** @var \Drupal\iso3166\Plugin\ContinentManager $pluginManager */
  $pluginManager = \Drupal::service('plugin.manager.continent');

  $europe = $pluginManager->getContinent('EU');
  $allContinents = $pluginManager->getContinents();

```

#### Using the service.

[](#using-the-service)

The service provides several methods to work with country and continent data.

```
  /** @var \Drupal\iso3166\Iso3166 $service */
  $service = \Drupal::service('iso3166');

  $continentOfBelgium = $service->getContinentByCountry('BE');
  $allCountriesInEurope = $service->getCountriesByContinent('EU');

```

#### Changing plugin data.

[](#changing-plugin-data)

To change data from the plugin you need to provide an alter hook. Or if you don't like hooks, have a look at **hook\_event\_dispatcher** module and dispatch an iso3166\_country\_info\_alter event.

```
  /**
   * Implements hook_iso3166_country_info_alter().
   */
  function MY_MODULE_iso3166_country_info_alter(array &$definitions) {
    $definitions['country:BE']['label'] = t('Other name for belgium');
  }

```

#### Adding data.

[](#adding-data)

Since both continents, countries and county collections are plugin you can easily provide your own. Below example will add "Neverland" to the list of countries in Europe. But you can as well provide a new continent to add it to in the same manner.

```

  namespace Drupal\MY_MODULE\Plugin\iso3166\Country;

  use Drupal\Core\Annotation\Translation;
  use Drupal\iso3166\Annotation\Country;
  use Drupal\iso3166\Plugin\iso3166\Country\CountryPluginBase;

  /**
   * Provides a country.
   *
   * @Country(
   *   id = "country_neverland",
   *   label = @Translation("Neverland"),
   *   alpha2 = "NV",
   *   alpha3 = "NVL",
   *   numeric = "999",
   *   continent = "EU"
   * )
   */
  class Neverland extends CountryPluginBase {}

```

```

  namespace Drupal\MY_MODULE\Plugin\iso3166\Continent;

  use Drupal\Core\Annotation\Translation;
  use Drupal\iso3166\Annotation\Continent;
  use Drupal\iso3166\Plugin\Iso3166\Continent\ContinentPluginBase;

  /**
   * Provides a continent.
   *
   * @Continent(
   *   id = "continent_zealandia",
   *   label = @Translation("Zealandia"),
   *   alpha2 = "ZL",
   * )
   */
  class Zealandia extends ContinentPluginBase {}

```

```

    namespace Drupal\MY_MODULE\Plugin\iso3166\CountryCollection;

    use Drupal\Core\Annotation\Translation;
    use Drupal\iso3166\Annotation\CountryCollection;
    use Drupal\iso3166\Plugin\Iso3166\CountryCollection\CountryCollectionPluginBase;

    /**
     * Provides a country collection.
     *
     * @CountryCollection(
     *   id = "benelux",
     *   label = @Translation("Benelux"),
     *   countries={"BE","NL","LU"}
     * )
     */
    class Benelux extends CountryCollectionPluginBase {}

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~255 days

Total

2

Last Release

2020d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6be5968aa5130827168e9c866ac371aa7649a4fbacd44b8aa3c97ccd6899158c?d=identicon)[gertvdb](/maintainers/gertvdb)

---

Top Contributors

[![gertvdb](https://avatars.githubusercontent.com/u/7106435?v=4)](https://github.com/gertvdb "gertvdb (19 commits)")

---

Tags

drupal-8

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/gertvdb-iso3166/health.svg)

```
[![Health](https://phpackages.com/badges/gertvdb-iso3166/health.svg)](https://phpackages.com/packages/gertvdb-iso3166)
```

###  Alternatives

[omaressaouaf/laravel-id-generator

Generate custom incremental unique ids for Laravel

566.3k](/packages/omaressaouaf-laravel-id-generator)[infuse/libs

Solid libraries for rapid PHP development

1444.0k3](/packages/infuse-libs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
