You are here

public function CountryManager::getByProperty in Ubercart 8.4

Returns all uc_country config entities with the specified propertes.

For example: To obtain all enabled countries, use getByProperty(['status' => TRUE]). To obtain the country with the two-character ISO 3166 code of 'ES', use getByProperty(['alpha_2' => 'ES']). Any property/properties defined in \Drupal\uc_country\Entity\Country may be used. Keep in mind that in most cases these properties are <em>unique</em>, so this method will return only one country configuration entity.

Parameters

array $properties: An associative array where the keys are the property names and the values are the values those properties must have.

Return value

\Drupal\uc_country\Entity\Country An array of \Drupal\uc_country\Entity\Country configuration entities, keyed by Id.

Overrides CountryManagerInterface::getByProperty

File

uc_country/src/CountryManager.php, line 109

Class

CountryManager
Provides list of countries.

Namespace

Drupal\uc_country

Code

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;
}