function country_property in Countries 7.2
Same name and namespace in other branches
- 8 countries.module \country_property()
Helper function to help standardise the display of the core properties.
Parameters
object $country: A country object.
string $property: The requested property.
string $default: The default value to use if the property is not set or it is empty.
The cid and enabled flags ignore defaults. The cid value is always returned raw and enabled is either Enabled or Disabled strings.
bool $sanitize: Boolean to indicate whether an HTML safe version is required.
Return value
string|int Integer cid or string representation of other properties.
9 calls to country_property()
- CountriesBaseSetupTest::assertCountryListed in tests/
countries.test - CountriesFunctionsUnitTest::testCountriesPropertyLookup in tests/
countries.test - This test that the country property lookup is working.
- countries_admin_overview in ./
countries.admin.inc - Menu callback; Displays a list of all countries.
- countries_field_formatter_view in ./
countries.fields.inc - Implements hook_field_formatter_view().
- countries_get_properties in ./
countries.module - Callback for getting extra country properties.
File
- ./
countries.module, line 766 - Defines the field and entity information for countries.
Code
function country_property($country, $property, $default = NULL, $sanitize = TRUE) {
$output = NULL;
switch ($property) {
case 'cid':
return $country->cid;
case 'enabled':
return empty($country->enabled) ? t('Disabled') : t('Enabled');
case 'continent_code':
if (!empty($country->continent)) {
$output = $country->continent;
}
break;
case 'continent':
case 'continent_name':
$continents = countries_get_continents();
if (!empty($country->continent) && !empty($continents[$country->continent])) {
$output = $continents[$country->continent];
}
elseif (!isset($default)) {
$output = t('Unknown');
}
break;
case 'official_name':
if (!empty($country->official_name)) {
$output = $country->official_name;
}
elseif (!isset($default)) {
// Entity->label() returns an empty string if not set.
$output = $country
->label();
if (!$output) {
$output = NULL;
}
}
break;
case 'numcode':
// We do not need to sanitize this output.
if (!empty($country->numcode)) {
return theme('countries_number', array(
'country' => $country,
));
}
break;
case 'name':
// Entity->label() returns an empty string if not set.
$output = $country
->label();
if (!$output) {
$output = NULL;
}
break;
default:
if (!empty($country->{$property})) {
$output = $country->{$property};
}
}
if (!isset($output)) {
$output = isset($default) ? $default : '';
}
return $sanitize ? check_plain($output) : $output;
}