diff --git a/phone.module b/phone.module index 00dc3ff..abcb615 100644 --- a/phone.module +++ b/phone.module @@ -494,6 +494,10 @@ function phone_field_formatter_info() { 'label' => t('National'), 'description' => t('ITU-T Recommendation for National numbers. e.g., 044 668 1800 ext. 1000'), ), + 'phone_national_international' => $base + array( + 'label' => t('National then International'), + 'description' => t('ITU-T Recommendation for National numbers. e.g., 044 668 1800 ext. 1000 for the default country code. For all other country codes it will use ITU-T Recommendation for International numbers. e.g., +41 44 668 1800 ext. 1000. This must have a default country code set otherwise it will default to the phone_international formatter.'), + ), 'phone_e164' => $base + array( 'label' => t('E164'), 'description' => t('International without formatting, and without the extension. e.g., +41446681800'), @@ -515,6 +519,14 @@ function phone_field_formatter_settings_summary($field, $instance, $view_mode) { $summary = array(); + // Check to see if default country has been enabled. If it has not warn the + // user that all phone numbers will be formatted in the phone_international + // format as we cannot restrict them from selecting it in + // phone_field_formatter_info() + if ($display['type'] == 'phone_national_international' && !$instance['widget']['settings']['country_options']['enable_default_country']) { + $summary[] = t('A default country code has not been set for this field. This formatter requires a default country code. All phone numbers will be formatted using the International Formatter.'); + } + if ($settings['full_hcard']) { $summary[] = t('Output comment with full hCard support.'); } @@ -609,6 +621,16 @@ function phone_field_formatter_view($entity_type, $entity, $field, $instance, $l $settings = $display['settings']; $formatter = $display['type']; + // If this format is phone_national_internaltional get the default country + // code for this widget instance. Otherwise change to the + // phone_international format. + if ($formatter == 'phone_national_international' && $instance['widget']['settings']['country_options']['enable_default_country']) { + $default_country = $instance['widget']['settings']['country_options']['default_country']; + } + else { + $formatter = 'phone_international'; + } + $allowed_values = phone_comment_allowed_values($field, $instance, $entity_type, $entity); $components = array_filter($settings['components']); @@ -634,7 +656,19 @@ function phone_field_formatter_view($entity_type, $entity, $field, $instance, $l $comment_id = ''; } - $formatted_number = phone_libphonenumber_format($number, $countrycode, $extension, $formatter, $settings['allow_alpha']); + // If this format is phone_national_internaltional set the formatter to the + // libphone accepted formatter based on the contry code for the phone + // number and the default country code + if ($formatter == 'phone_national_international' && $default_country == $countrycode) { + $formatted_number = phone_libphonenumber_format($number, $countrycode, $extension, 'phone_national', $settings['allow_alpha']); + } + else if ($formatter == 'phone_national_international') { + $formatted_number = phone_libphonenumber_format($number, $countrycode, $extension, 'phone_international', $settings['allow_alpha']); + } + else { + $formatted_number = phone_libphonenumber_format($number, $countrycode, $extension, $formatter, $settings['allow_alpha']); + } + $link = $settings['as_tel_link']; $href = 'tel:' . phone_libphonenumber_format($number, $countrycode, $extension, 'phone_rfc3966');