address-hide-country.inc in Address Field 7
File
plugins/format/address-hide-country.inc
View source
<?php
$plugin = array(
'title' => t('Hide the country when only one is available'),
'format callback' => 'addressfield_format_address_hide_country',
'type' => 'address',
'weight' => -80,
);
function addressfield_format_address_hide_country(&$format, $address, $context = array()) {
if ($context['mode'] == 'form' && (empty($context['instance']) || $context['instance']['required'])) {
if (!empty($format['country']['#options']) && count($format['country']['#options']) == 1) {
$format['country']['#access'] = FALSE;
}
}
elseif ($context['mode'] == 'render') {
if (!empty($context['instance']['widget']['settings']['available_countries']) && count($context['instance']['widget']['settings']['available_countries']) == 1) {
if (isset($context['instance']['widget']['settings']['available_countries'][$address['country']])) {
$format['country']['#access'] = FALSE;
}
}
}
}