Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Core\Locale;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Extension\ModuleHandlerInterface;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Provides list of countries.
|
Chris@0
|
9 */
|
Chris@0
|
10 class CountryManager implements CountryManagerInterface {
|
Chris@0
|
11
|
Chris@0
|
12 /**
|
Chris@0
|
13 * The module handler service.
|
Chris@0
|
14 *
|
Chris@0
|
15 * @var \Drupal\Core\Extension\ModuleHandlerInterface
|
Chris@0
|
16 */
|
Chris@0
|
17 protected $moduleHandler;
|
Chris@0
|
18
|
Chris@0
|
19 /**
|
Chris@0
|
20 * An array of country code => country name pairs.
|
Chris@0
|
21 */
|
Chris@0
|
22 protected $countries;
|
Chris@0
|
23
|
Chris@0
|
24 /**
|
Chris@0
|
25 * Constructor.
|
Chris@0
|
26 *
|
Chris@0
|
27 * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
|
Chris@0
|
28 */
|
Chris@0
|
29 public function __construct(ModuleHandlerInterface $module_handler) {
|
Chris@0
|
30 $this->moduleHandler = $module_handler;
|
Chris@0
|
31 }
|
Chris@0
|
32
|
Chris@0
|
33 /**
|
Chris@0
|
34 * Get an array of all two-letter country code => country name pairs.
|
Chris@0
|
35 *
|
Chris@0
|
36 * @return array
|
Chris@0
|
37 * An array of country code => country name pairs.
|
Chris@0
|
38 */
|
Chris@0
|
39 public static function getStandardList() {
|
Chris@0
|
40 $countries = [
|
Chris@0
|
41 'AC' => t('Ascension Island'),
|
Chris@0
|
42 'AD' => t('Andorra'),
|
Chris@0
|
43 'AE' => t('United Arab Emirates'),
|
Chris@0
|
44 'AF' => t('Afghanistan'),
|
Chris@0
|
45 'AG' => t('Antigua and Barbuda'),
|
Chris@0
|
46 'AI' => t('Anguilla'),
|
Chris@0
|
47 'AL' => t('Albania'),
|
Chris@0
|
48 'AM' => t('Armenia'),
|
Chris@0
|
49 'AN' => t('Netherlands Antilles'),
|
Chris@0
|
50 'AO' => t('Angola'),
|
Chris@0
|
51 'AQ' => t('Antarctica'),
|
Chris@0
|
52 'AR' => t('Argentina'),
|
Chris@0
|
53 'AS' => t('American Samoa'),
|
Chris@0
|
54 'AT' => t('Austria'),
|
Chris@0
|
55 'AU' => t('Australia'),
|
Chris@0
|
56 'AW' => t('Aruba'),
|
Chris@0
|
57 'AX' => t('Åland Islands'),
|
Chris@0
|
58 'AZ' => t('Azerbaijan'),
|
Chris@0
|
59 'BA' => t('Bosnia and Herzegovina'),
|
Chris@0
|
60 'BB' => t('Barbados'),
|
Chris@0
|
61 'BD' => t('Bangladesh'),
|
Chris@0
|
62 'BE' => t('Belgium'),
|
Chris@0
|
63 'BF' => t('Burkina Faso'),
|
Chris@0
|
64 'BG' => t('Bulgaria'),
|
Chris@0
|
65 'BH' => t('Bahrain'),
|
Chris@0
|
66 'BI' => t('Burundi'),
|
Chris@0
|
67 'BJ' => t('Benin'),
|
Chris@0
|
68 'BL' => t('Saint Barthélemy'),
|
Chris@0
|
69 'BM' => t('Bermuda'),
|
Chris@0
|
70 'BN' => t('Brunei'),
|
Chris@0
|
71 'BO' => t('Bolivia'),
|
Chris@0
|
72 'BQ' => t('Caribbean Netherlands'),
|
Chris@0
|
73 'BR' => t('Brazil'),
|
Chris@0
|
74 'BS' => t('Bahamas'),
|
Chris@0
|
75 'BT' => t('Bhutan'),
|
Chris@0
|
76 'BV' => t('Bouvet Island'),
|
Chris@0
|
77 'BW' => t('Botswana'),
|
Chris@0
|
78 'BY' => t('Belarus'),
|
Chris@0
|
79 'BZ' => t('Belize'),
|
Chris@0
|
80 'CA' => t('Canada'),
|
Chris@0
|
81 'CC' => t('Cocos [Keeling] Islands'),
|
Chris@0
|
82 'CD' => t('Congo - Kinshasa'),
|
Chris@0
|
83 'CF' => t('Central African Republic'),
|
Chris@0
|
84 'CG' => t('Congo - Brazzaville'),
|
Chris@0
|
85 'CH' => t('Switzerland'),
|
Chris@0
|
86 'CI' => t('Côte d’Ivoire'),
|
Chris@0
|
87 'CK' => t('Cook Islands'),
|
Chris@0
|
88 'CL' => t('Chile'),
|
Chris@0
|
89 'CM' => t('Cameroon'),
|
Chris@0
|
90 'CN' => t('China'),
|
Chris@0
|
91 'CO' => t('Colombia'),
|
Chris@0
|
92 'CP' => t('Clipperton Island'),
|
Chris@0
|
93 'CR' => t('Costa Rica'),
|
Chris@0
|
94 'CU' => t('Cuba'),
|
Chris@0
|
95 'CV' => t('Cape Verde'),
|
Chris@0
|
96 'CW' => t('Curaçao'),
|
Chris@0
|
97 'CX' => t('Christmas Island'),
|
Chris@0
|
98 'CY' => t('Cyprus'),
|
Chris@0
|
99 'CZ' => t('Czech Republic'),
|
Chris@0
|
100 'DE' => t('Germany'),
|
Chris@0
|
101 'DG' => t('Diego Garcia'),
|
Chris@0
|
102 'DJ' => t('Djibouti'),
|
Chris@0
|
103 'DK' => t('Denmark'),
|
Chris@0
|
104 'DM' => t('Dominica'),
|
Chris@0
|
105 'DO' => t('Dominican Republic'),
|
Chris@0
|
106 'DZ' => t('Algeria'),
|
Chris@0
|
107 'EA' => t('Ceuta and Melilla'),
|
Chris@0
|
108 'EC' => t('Ecuador'),
|
Chris@0
|
109 'EE' => t('Estonia'),
|
Chris@0
|
110 'EG' => t('Egypt'),
|
Chris@0
|
111 'EH' => t('Western Sahara'),
|
Chris@0
|
112 'ER' => t('Eritrea'),
|
Chris@0
|
113 'ES' => t('Spain'),
|
Chris@0
|
114 'ET' => t('Ethiopia'),
|
Chris@0
|
115 'FI' => t('Finland'),
|
Chris@0
|
116 'FJ' => t('Fiji'),
|
Chris@0
|
117 'FK' => t('Falkland Islands'),
|
Chris@0
|
118 'FM' => t('Micronesia'),
|
Chris@0
|
119 'FO' => t('Faroe Islands'),
|
Chris@0
|
120 'FR' => t('France'),
|
Chris@0
|
121 'GA' => t('Gabon'),
|
Chris@0
|
122 'GB' => t('United Kingdom'),
|
Chris@0
|
123 'GD' => t('Grenada'),
|
Chris@0
|
124 'GE' => t('Georgia'),
|
Chris@0
|
125 'GF' => t('French Guiana'),
|
Chris@0
|
126 'GG' => t('Guernsey'),
|
Chris@0
|
127 'GH' => t('Ghana'),
|
Chris@0
|
128 'GI' => t('Gibraltar'),
|
Chris@0
|
129 'GL' => t('Greenland'),
|
Chris@0
|
130 'GM' => t('Gambia'),
|
Chris@0
|
131 'GN' => t('Guinea'),
|
Chris@0
|
132 'GP' => t('Guadeloupe'),
|
Chris@0
|
133 'GQ' => t('Equatorial Guinea'),
|
Chris@0
|
134 'GR' => t('Greece'),
|
Chris@0
|
135 'GS' => t('South Georgia and the South Sandwich Islands'),
|
Chris@0
|
136 'GT' => t('Guatemala'),
|
Chris@0
|
137 'GU' => t('Guam'),
|
Chris@0
|
138 'GW' => t('Guinea-Bissau'),
|
Chris@0
|
139 'GY' => t('Guyana'),
|
Chris@0
|
140 'HK' => t('Hong Kong SAR China'),
|
Chris@0
|
141 'HM' => t('Heard Island and McDonald Islands'),
|
Chris@0
|
142 'HN' => t('Honduras'),
|
Chris@0
|
143 'HR' => t('Croatia'),
|
Chris@0
|
144 'HT' => t('Haiti'),
|
Chris@0
|
145 'HU' => t('Hungary'),
|
Chris@0
|
146 'IC' => t('Canary Islands'),
|
Chris@0
|
147 'ID' => t('Indonesia'),
|
Chris@0
|
148 'IE' => t('Ireland'),
|
Chris@0
|
149 'IL' => t('Israel'),
|
Chris@0
|
150 'IM' => t('Isle of Man'),
|
Chris@0
|
151 'IN' => t('India'),
|
Chris@0
|
152 'IO' => t('British Indian Ocean Territory'),
|
Chris@0
|
153 'IQ' => t('Iraq'),
|
Chris@0
|
154 'IR' => t('Iran'),
|
Chris@0
|
155 'IS' => t('Iceland'),
|
Chris@0
|
156 'IT' => t('Italy'),
|
Chris@0
|
157 'JE' => t('Jersey'),
|
Chris@0
|
158 'JM' => t('Jamaica'),
|
Chris@0
|
159 'JO' => t('Jordan'),
|
Chris@0
|
160 'JP' => t('Japan'),
|
Chris@0
|
161 'KE' => t('Kenya'),
|
Chris@0
|
162 'KG' => t('Kyrgyzstan'),
|
Chris@0
|
163 'KH' => t('Cambodia'),
|
Chris@0
|
164 'KI' => t('Kiribati'),
|
Chris@0
|
165 'KM' => t('Comoros'),
|
Chris@0
|
166 'KN' => t('Saint Kitts and Nevis'),
|
Chris@0
|
167 'KP' => t('North Korea'),
|
Chris@0
|
168 'KR' => t('South Korea'),
|
Chris@0
|
169 'KW' => t('Kuwait'),
|
Chris@0
|
170 'KY' => t('Cayman Islands'),
|
Chris@0
|
171 'KZ' => t('Kazakhstan'),
|
Chris@0
|
172 'LA' => t('Laos'),
|
Chris@0
|
173 'LB' => t('Lebanon'),
|
Chris@0
|
174 'LC' => t('Saint Lucia'),
|
Chris@0
|
175 'LI' => t('Liechtenstein'),
|
Chris@0
|
176 'LK' => t('Sri Lanka'),
|
Chris@0
|
177 'LR' => t('Liberia'),
|
Chris@0
|
178 'LS' => t('Lesotho'),
|
Chris@0
|
179 'LT' => t('Lithuania'),
|
Chris@0
|
180 'LU' => t('Luxembourg'),
|
Chris@0
|
181 'LV' => t('Latvia'),
|
Chris@0
|
182 'LY' => t('Libya'),
|
Chris@0
|
183 'MA' => t('Morocco'),
|
Chris@0
|
184 'MC' => t('Monaco'),
|
Chris@0
|
185 'MD' => t('Moldova'),
|
Chris@0
|
186 'ME' => t('Montenegro'),
|
Chris@0
|
187 'MF' => t('Saint Martin'),
|
Chris@0
|
188 'MG' => t('Madagascar'),
|
Chris@0
|
189 'MH' => t('Marshall Islands'),
|
Chris@0
|
190 'MK' => t('Macedonia'),
|
Chris@0
|
191 'ML' => t('Mali'),
|
Chris@0
|
192 'MM' => t('Myanmar [Burma]'),
|
Chris@0
|
193 'MN' => t('Mongolia'),
|
Chris@0
|
194 'MO' => t('Macau SAR China'),
|
Chris@0
|
195 'MP' => t('Northern Mariana Islands'),
|
Chris@0
|
196 'MQ' => t('Martinique'),
|
Chris@0
|
197 'MR' => t('Mauritania'),
|
Chris@0
|
198 'MS' => t('Montserrat'),
|
Chris@0
|
199 'MT' => t('Malta'),
|
Chris@0
|
200 'MU' => t('Mauritius'),
|
Chris@0
|
201 'MV' => t('Maldives'),
|
Chris@0
|
202 'MW' => t('Malawi'),
|
Chris@0
|
203 'MX' => t('Mexico'),
|
Chris@0
|
204 'MY' => t('Malaysia'),
|
Chris@0
|
205 'MZ' => t('Mozambique'),
|
Chris@0
|
206 'NA' => t('Namibia'),
|
Chris@0
|
207 'NC' => t('New Caledonia'),
|
Chris@0
|
208 'NE' => t('Niger'),
|
Chris@0
|
209 'NF' => t('Norfolk Island'),
|
Chris@0
|
210 'NG' => t('Nigeria'),
|
Chris@0
|
211 'NI' => t('Nicaragua'),
|
Chris@0
|
212 'NL' => t('Netherlands'),
|
Chris@0
|
213 'NO' => t('Norway'),
|
Chris@0
|
214 'NP' => t('Nepal'),
|
Chris@0
|
215 'NR' => t('Nauru'),
|
Chris@0
|
216 'NU' => t('Niue'),
|
Chris@0
|
217 'NZ' => t('New Zealand'),
|
Chris@0
|
218 'OM' => t('Oman'),
|
Chris@0
|
219 'PA' => t('Panama'),
|
Chris@0
|
220 'PE' => t('Peru'),
|
Chris@0
|
221 'PF' => t('French Polynesia'),
|
Chris@0
|
222 'PG' => t('Papua New Guinea'),
|
Chris@0
|
223 'PH' => t('Philippines'),
|
Chris@0
|
224 'PK' => t('Pakistan'),
|
Chris@0
|
225 'PL' => t('Poland'),
|
Chris@0
|
226 'PM' => t('Saint Pierre and Miquelon'),
|
Chris@0
|
227 'PN' => t('Pitcairn Islands'),
|
Chris@0
|
228 'PR' => t('Puerto Rico'),
|
Chris@0
|
229 'PS' => t('Palestinian Territories'),
|
Chris@0
|
230 'PT' => t('Portugal'),
|
Chris@0
|
231 'PW' => t('Palau'),
|
Chris@0
|
232 'PY' => t('Paraguay'),
|
Chris@0
|
233 'QA' => t('Qatar'),
|
Chris@0
|
234 'QO' => t('Outlying Oceania'),
|
Chris@0
|
235 'RE' => t('Réunion'),
|
Chris@0
|
236 'RO' => t('Romania'),
|
Chris@0
|
237 'RS' => t('Serbia'),
|
Chris@0
|
238 'RU' => t('Russia'),
|
Chris@0
|
239 'RW' => t('Rwanda'),
|
Chris@0
|
240 'SA' => t('Saudi Arabia'),
|
Chris@0
|
241 'SB' => t('Solomon Islands'),
|
Chris@0
|
242 'SC' => t('Seychelles'),
|
Chris@0
|
243 'SD' => t('Sudan'),
|
Chris@0
|
244 'SE' => t('Sweden'),
|
Chris@0
|
245 'SG' => t('Singapore'),
|
Chris@0
|
246 'SH' => t('Saint Helena'),
|
Chris@0
|
247 'SI' => t('Slovenia'),
|
Chris@0
|
248 'SJ' => t('Svalbard and Jan Mayen'),
|
Chris@0
|
249 'SK' => t('Slovakia'),
|
Chris@0
|
250 'SL' => t('Sierra Leone'),
|
Chris@0
|
251 'SM' => t('San Marino'),
|
Chris@0
|
252 'SN' => t('Senegal'),
|
Chris@0
|
253 'SO' => t('Somalia'),
|
Chris@0
|
254 'SR' => t('Suriname'),
|
Chris@0
|
255 'SS' => t('South Sudan'),
|
Chris@0
|
256 'ST' => t('São Tomé and Príncipe'),
|
Chris@0
|
257 'SV' => t('El Salvador'),
|
Chris@0
|
258 'SX' => t('Sint Maarten'),
|
Chris@0
|
259 'SY' => t('Syria'),
|
Chris@0
|
260 'SZ' => t('Swaziland'),
|
Chris@0
|
261 'TA' => t('Tristan da Cunha'),
|
Chris@0
|
262 'TC' => t('Turks and Caicos Islands'),
|
Chris@0
|
263 'TD' => t('Chad'),
|
Chris@0
|
264 'TF' => t('French Southern Territories'),
|
Chris@0
|
265 'TG' => t('Togo'),
|
Chris@0
|
266 'TH' => t('Thailand'),
|
Chris@0
|
267 'TJ' => t('Tajikistan'),
|
Chris@0
|
268 'TK' => t('Tokelau'),
|
Chris@0
|
269 'TL' => t('Timor-Leste'),
|
Chris@0
|
270 'TM' => t('Turkmenistan'),
|
Chris@0
|
271 'TN' => t('Tunisia'),
|
Chris@0
|
272 'TO' => t('Tonga'),
|
Chris@0
|
273 'TR' => t('Turkey'),
|
Chris@0
|
274 'TT' => t('Trinidad and Tobago'),
|
Chris@0
|
275 'TV' => t('Tuvalu'),
|
Chris@0
|
276 'TW' => t('Taiwan'),
|
Chris@0
|
277 'TZ' => t('Tanzania'),
|
Chris@0
|
278 'UA' => t('Ukraine'),
|
Chris@0
|
279 'UG' => t('Uganda'),
|
Chris@0
|
280 'UM' => t('U.S. Outlying Islands'),
|
Chris@0
|
281 'US' => t('United States'),
|
Chris@0
|
282 'UY' => t('Uruguay'),
|
Chris@0
|
283 'UZ' => t('Uzbekistan'),
|
Chris@0
|
284 'VA' => t('Vatican City'),
|
Chris@0
|
285 'VC' => t('Saint Vincent and the Grenadines'),
|
Chris@0
|
286 'VE' => t('Venezuela'),
|
Chris@0
|
287 'VG' => t('British Virgin Islands'),
|
Chris@0
|
288 'VI' => t('U.S. Virgin Islands'),
|
Chris@0
|
289 'VN' => t('Vietnam'),
|
Chris@0
|
290 'VU' => t('Vanuatu'),
|
Chris@0
|
291 'WF' => t('Wallis and Futuna'),
|
Chris@0
|
292 'WS' => t('Samoa'),
|
Chris@0
|
293 'XK' => t('Kosovo'),
|
Chris@0
|
294 'YE' => t('Yemen'),
|
Chris@0
|
295 'YT' => t('Mayotte'),
|
Chris@0
|
296 'ZA' => t('South Africa'),
|
Chris@0
|
297 'ZM' => t('Zambia'),
|
Chris@0
|
298 'ZW' => t('Zimbabwe'),
|
Chris@0
|
299 ];
|
Chris@0
|
300
|
Chris@0
|
301 // Sort the list.
|
Chris@0
|
302 natcasesort($countries);
|
Chris@0
|
303
|
Chris@0
|
304 return $countries;
|
Chris@0
|
305 }
|
Chris@0
|
306
|
Chris@0
|
307 /**
|
Chris@0
|
308 * Get an array of country code => country name pairs, altered by alter hooks.
|
Chris@0
|
309 *
|
Chris@0
|
310 * @return array
|
Chris@0
|
311 * An array of country code => country name pairs.
|
Chris@0
|
312 *
|
Chris@0
|
313 * @see \Drupal\Core\Locale\CountryManager::getStandardList()
|
Chris@0
|
314 */
|
Chris@0
|
315 public function getList() {
|
Chris@0
|
316 // Populate the country list if it is not already populated.
|
Chris@0
|
317 if (!isset($this->countries)) {
|
Chris@0
|
318 $this->countries = static::getStandardList();
|
Chris@0
|
319 $this->moduleHandler->alter('countries', $this->countries);
|
Chris@0
|
320 }
|
Chris@0
|
321
|
Chris@0
|
322 return $this->countries;
|
Chris@0
|
323 }
|
Chris@0
|
324
|
Chris@0
|
325 }
|