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
| Method | Description |
|---|---|
by_code() | Every country as ISO 3166-1 alpha-2 code => name. |
by_name() | Every country as name => ISO 3166-1 alpha-2 code. |
code_for() | The ISO 3166-1 alpha-2 code for a country named either way. |
name_for() | The name for a country named either way, for a destination whose list is keyed by name. |
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
code_for()
public static function code_for( string $country ): string
The ISO 3166-1 alpha-2 code for a country named either way.
Gravity Forms stores a country default in two spellings, and which one it is depends on
where it was written: the editor's per-input "Default Values" box takes what its dropdown
shows, which is the NAME, while the field-level defaultCountry is converted to the CODE
on save (GF_Field_Address::sanitize_settings, class-gf-field-address.php:1402-1404). A
destination selects on one or the other and never on both, so the pair has to be resolved
before it is written rather than passed through and hoped for.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$country | string | A country name or an alpha-2 code. |
Returns
string— The code, or the value unchanged when this list names no such country -- which includes the case of Gravity Forms not being loaded to supply a list. Writing it unchanged leaves a dropdown selecting nothing, the same as writing nothing, and leaves the value where somebody can see it.
Since: %ver%
Source: src/Schema/GfCountries.php:95
name_for()
public static function name_for( string $country ): string
The name for a country named either way, for a destination whose list is keyed by name.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$country | string | A country name or an alpha-2 code. |
Returns
string— The name, or the value unchanged when this list names no such country.
Since: %ver%
Source: src/Schema/GfCountries.php:108