From 4bab6eb17b3fcf3bc5a58b6d2824db976850c75f Mon Sep 17 00:00:00 2001 From: Eli Van Zoeren Date: Wed, 14 Jun 2017 21:33:24 -0400 Subject: [PATCH] Added `craft.vzAddress.countries` variable containing an array of all the countries in the world --- README.md | 10 ++++++++++ changelog.json | 8 ++++++++ vzaddress/VzAddressPlugin.php | 2 +- vzaddress/fieldtypes/VzAddressFieldType.php | 17 ++--------------- vzaddress/services/VzAddressService.php | 18 ++++++++++++++++++ vzaddress/variables/VzAddressVariable.php | 15 +++++++++++++++ 6 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 vzaddress/services/VzAddressService.php create mode 100644 vzaddress/variables/VzAddressVariable.php diff --git a/README.md b/README.md index 1bbc06f..4549303 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,16 @@ Accepts the same parameters as `staticMapUrl`. * The options array mirrors the [MapOptions](https://developers.google.com/maps/documentation/javascript/3.exp/reference#MapOptions) configuration from Google Maps Javascript API. All available options are shown in the example above. Only the `width`, `height`, & `zoom` options are set by default. * The icon array is used for configuring the look of the marker icon. All available options are shown in the example above. +### Bonus: Output a list of all countries + +VZ Address makes available an array of all countries indexed by their country code as `craft.vzAddress.countries`. You can use this to generate your frontend entry form, or wherever you may need a list of all the countries in the world. + + + Installation ------------ diff --git a/changelog.json b/changelog.json index f44e41b..a5830c3 100644 --- a/changelog.json +++ b/changelog.json @@ -1,4 +1,12 @@ [ + { + "version": "1.5.0", + "downloadUrl": "https://github.com/elivz/VzAddress-Craft/archive/1.5.0.zip", + "date": "2017-06-14T21:30:00+00:00", + "notes": [ + "[Added] `craft.vzAddress.countries` variable containing an array of all the countries in the world." + ] + }, { "version": "1.4.2", "downloadUrl": "https://github.com/elivz/VzAddress-Craft/archive/1.4.2.zip", diff --git a/vzaddress/VzAddressPlugin.php b/vzaddress/VzAddressPlugin.php index 1b9ffa0..43aaf01 100644 --- a/vzaddress/VzAddressPlugin.php +++ b/vzaddress/VzAddressPlugin.php @@ -11,7 +11,7 @@ public function getName() { } public function getVersion() { - return '1.4.2'; + return '1.5.0'; } public function getSchemaVersion() { diff --git a/vzaddress/fieldtypes/VzAddressFieldType.php b/vzaddress/fieldtypes/VzAddressFieldType.php index b875686..41b3a57 100644 --- a/vzaddress/fieldtypes/VzAddressFieldType.php +++ b/vzaddress/fieldtypes/VzAddressFieldType.php @@ -6,8 +6,6 @@ */ class VzAddressFieldType extends BaseFieldType implements IPreviewableFieldType { - protected $countryCodes = array('AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BQ', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'KH', 'CM', 'CA', 'CV', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC', 'CO', 'KM', 'CG', 'CD', 'CK', 'CR', 'CI', 'HR', 'CU', 'CW', 'CY', 'CZ', 'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK', 'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GG', 'GN', 'GW', 'GY', 'HT', 'HM', 'VA', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IM', 'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KE', 'KI', 'KP', 'KR', 'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'YT', 'MX', 'FM', 'MD', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP', 'NL', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'MP', 'NO', 'OM', 'PK', 'PW', 'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA', 'RE', 'RO', 'RU', 'RW', 'BL', 'SH', 'KN', 'LC', 'MF', 'PM', 'VC', 'WS', 'SM', 'ST', 'SA', 'SN', 'RS', 'SC', 'SL', 'SG', 'SX', 'SK', 'SI', 'SB', 'SO', 'ZA', 'GS', 'SS', 'ES', 'LK', 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR', 'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'US', 'UM', 'UY', 'UZ', 'VU', 'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW'); - public function getName() { return Craft::t('Address'); } @@ -26,7 +24,7 @@ protected function defineSettings() { } public function getSettingsHtml() { - $countries = $this->_getCountryNames(); + $countries = craft()->vzAddress->getCountries(); return craft()->templates->render('vzaddress/fieldtype/settings', array( 'settings' => $this->getSettings(), @@ -53,7 +51,7 @@ public function getInputHtml($name, $value) { craft()->templates->includeJsResource('vzaddress/js/input.js'); craft()->templates->includeJs("$('#{$namespacedId}').vzAddress();"); - $countries = $this->_getCountryNames(); + $countries = craft()->vzAddress->getCountries(); return craft()->templates->render('vzaddress/fieldtype/input', array( 'id' => $inputId, @@ -77,15 +75,4 @@ public function getTableAttributeHtml($value) { return $value->html(); } } - - private function _getCountryNames() { - $localeData = craft()->i18n->getLocaleData(); - $countries = array(); - - foreach ($this->countryCodes as $code) { - $countries[$code] = $localeData->getTerritory($code); - } - - return $countries; - } } diff --git a/vzaddress/services/VzAddressService.php b/vzaddress/services/VzAddressService.php new file mode 100644 index 0000000..93dcf9e --- /dev/null +++ b/vzaddress/services/VzAddressService.php @@ -0,0 +1,18 @@ +i18n->getLocaleData(); + $countries = array(); + + foreach ($this->countryCodes as $code) { + $countries[$code] = $localeData->getTerritory($code); + } + + return $countries; + } +} diff --git a/vzaddress/variables/VzAddressVariable.php b/vzaddress/variables/VzAddressVariable.php new file mode 100644 index 0000000..b8fa179 --- /dev/null +++ b/vzaddress/variables/VzAddressVariable.php @@ -0,0 +1,15 @@ +vzAddress->getCountries(); + } +} \ No newline at end of file