class CountryManager in Ubercart 8.4
Provides list of countries.
Hierarchy
- class \Drupal\uc_country\CountryManager implements CountryManagerInterface uses StringTranslationTrait
Expanded class hierarchy of CountryManager
File
- uc_country/
src/ CountryManager.php, line 14
Namespace
Drupal\uc_countryView source
class CountryManager implements CountryManagerInterface {
use StringTranslationTrait;
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Stores the entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* An array of country code => country name pairs.
*
* @var array
*/
protected $countries;
/**
* Constructor.
*
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(ModuleHandlerInterface $module_handler, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->moduleHandler = $module_handler;
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public function getList() {
// Populate the country list if it is not already populated.
if (!isset($this->countries)) {
$this->countries = CoreCountryManager::getStandardList();
$this->moduleHandler
->alter('countries', $this->countries);
}
return $this->countries;
}
/**
* {@inheritdoc}
*/
public function getAvailableList() {
$countries = $this->entityTypeManager
->getStorage('uc_country')
->loadMultiple(NULL);
$country_names = [];
foreach ($countries as $alpha_2 => $country) {
// We can use non-literals in t() here because the country names are
// defined in configuration files, so they have been translated.
$country_names[$alpha_2] = $this
->t($country
->getName());
}
natcasesort($country_names);
$this->moduleHandler
->alter('countries', $country_names);
return $country_names;
}
/**
* {@inheritdoc}
*/
public function getEnabledList() {
$countries = $this->entityTypeManager
->getStorage('uc_country')
->loadByProperties([
'status' => TRUE,
]);
$country_names = [];
foreach ($countries as $alpha_2 => $country) {
// We can use non-literals in t() here because the country names are
// defined in configuration files, so they have been translated.
$country_names[$alpha_2] = $this
->t($country
->getName());
}
natcasesort($country_names);
$this->moduleHandler
->alter('countries', $country_names);
return $country_names;
}
/**
* {@inheritdoc}
*/
public function getCountry($alpha_2) {
return $this->entityTypeManager
->getStorage('uc_country')
->load($alpha_2);
}
/**
* {@inheritdoc}
*/
public function getByProperty(array $properties) {
$countries = $this->entityTypeManager
->getStorage('uc_country')
->loadByProperties($properties);
$country_names = [];
foreach ($countries as $alpha_2 => $country) {
// We can use non-literals in t() here because the country names are
// defined in configuration files, so they have been translated.
$country_names[$alpha_2] = $this
->t($country
->getName());
}
natcasesort($country_names);
return $country_names;
}
/**
* {@inheritdoc}
*/
public function getZoneList($alpha_2) {
if ($country = $this->entityTypeManager
->getStorage('uc_country')
->load($alpha_2)) {
return $country
->getZones();
}
return [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CountryManager:: |
protected | property | An array of country code => country name pairs. | |
CountryManager:: |
protected | property | Stores the entity type manager. | |
CountryManager:: |
protected | property | The module handler service. | |
CountryManager:: |
public | function |
Returns a list of all available country code => country name pairs. Overrides CountryManagerInterface:: |
|
CountryManager:: |
public | function |
Returns all uc_country config entities with the specified propertes. Overrides CountryManagerInterface:: |
|
CountryManager:: |
public | function |
Returns the uc_country config entity with the specified country code. Overrides CountryManagerInterface:: |
|
CountryManager:: |
public | function |
Returns a list of country code => country name pairs for enabled countries. Overrides CountryManagerInterface:: |
|
CountryManager:: |
public | function |
Returns a list of country code => country name pairs. Overrides CountryManagerInterface:: |
|
CountryManager:: |
public | function |
Returns a list of zone code => zone name pairs for the specified country. Overrides CountryManagerInterface:: |
|
CountryManager:: |
public | function | Constructor. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |