Our site's user base is primarily part of the default country (US), however we do have a few users with phone numbers for other countries. It doesn't make sense to format all of the phone numbers with +1 for the handful of non-US cases and setting everything to national causes confusion when looking at the few international numbers as the country code is needed in those instances. To deal with this I've developed a formatting option that checks against the default country and if it's the same as the country code for the phone number then the formatting function is passed phone_national, otherwise it gets phone_international.
Attached is a patch that is the first step for this. It still needs some more work on the settings form to require a default country if this formatter is selected, but I wanted to share what I have.
Comments
Comment #1
ejustice CreditAttribution: ejustice commentedI've added a check to ensure that 'Enable default country code' is set and if it isn't then the code is setting the formatter to phone_international. Additionally I've got phone_field_formatter_settings_summary() checking to see if 'Enable default country code' is checked and if not a note is being put into the information displayed in the summary to tell the user that all numbers will be formatted using phone_interntional unless a default country code is set.
I don't think this is the ideal way to handle this however I haven't found a way to prevent phone_field_formatter_info() from presenting phone_national_international as an option as that hook doesn't have any information about the widgets that are using it and the function is cached long before the field display page is being loaded, so what is correct for one instance may not be for another.
Comment #2
ejustice CreditAttribution: ejustice commentedI found a bug with the code in #2 where a second phone number for the same user will always be formatted as international. Attached is a patch without that issue.
Comment #3
cweagansThis looks pretty good, but before we commit this, can you remove trailing whitespace please?
Comment #4
ejustice CreditAttribution: ejustice commentedHere it is.
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedThanks for this.
In order to get this to work, I had to make the following changes:
changed to:
&
changed to:
i.e., remove '
['widget']
'.In addition, I changed the following:
to
i.e., I added $settings['extension_prefix'] to the parameters.
I applied these manually since the patch failed against the latest dev. I hope this report is helpful.