Skip to main content

GravityKit\GravityMigrate\Schema\GfCountries

Names every country, the way Gravity Forms names them.

A country dropdown is one of the few fields whose contents have to be migrated rather than just its settings, and no source form carries the list: Fluent stores a two-entry placeholder its renderer throws away, Ninja replaces the stored options outright on render. So each adapter has to rebuild the list, and the only list guaranteed to be present during a migration is the hub's -- Gravity Forms is running by definition, while the source plugin usually is not, because the ordinary case is an import from an exported file.

An adapter still prefers its own vendor's list where one is loaded, because that is the list the source form was built against; this is the fallback.

Gravity Forms keys its list by the ISO 3166-1 alpha-2 code (GF_Field_Address::get_default_countries, includes/fields/class-gf-field-address.php:662), sorts it by name in the site's locale and passes it through the gform_countries filter before returning it (:633). A site that has filtered its own list therefore migrates against that list, which is the one its forms actually offer.

Since: %ver%

Source: src/Schema/GfCountries.php:33

Details

  • Kind: class
  • Namespace: GravityKit\GravityMigrate\Schema

Methods

MethodDescription
by_code()Every country as ISO 3166-1 alpha-2 code => name.
by_name()Every country as name => ISO 3166-1 alpha-2 code.

Method Reference

by_code()

public static function by_code(): array

Every country as ISO 3166-1 alpha-2 code => name.

Returns

  • array<string, — string> Empty when Gravity Forms is not loaded. An empty list is indistinguishable from a missing one downstream, so a caller building a dropdown from it should report instead of shipping an empty dropdown.

Since: %ver%

Source: src/Schema/GfCountries.php:45

by_name()

public static function by_name(): array

Every country as name => ISO 3166-1 alpha-2 code.

The inverse of \self::by_code(), for a platform that keys its own list by name -- Ninja Forms does (includes/Config/CountryList.php). Names are unique within one list, so the flip loses nothing.

Returns

  • array<string, — string> Empty when Gravity Forms is not loaded.

Since: %ver%

Source: src/Schema/GfCountries.php:70