/** * */ private function getRandomCountryInfo($type = NULL) { include_once DRUPAL_ROOT . '/includes/locale.inc'; $manager = new CountryManager($this->getModuleHandler()); $countries = $manager->getList(); uksort($countries, function () { return rand() > rand(); }); $country = array_slice($countries, 0, 1); $value = array('code' => key($country), 'name' => reset($country)); if (is_null($type)) { return $value; } return isset($value[$type]) ? $value[$type] : $value; }
/** * {@inheritdoc} */ public function getList() { // Populate the country list if it is not already populated. if (!isset($this->countries)) { $this->countries = \Drupal\Core\Locale\CountryManager::getStandardList(); $this->moduleHandler->alter('countries', $this->countries); } return $this->countries; }