Problem/Motivation
One of the biggest challenges with the current Telephone module is that it's just a glorified textfield. It has no option to normalize the telephone number - either for the purpose of validation or formatting.
In Commerce applications, we see more and more requirements from payment gateways to collect and pass the telephone number to the payment gateway during Checkout. Given we have payment gateways from all over the world, supporting customers in virtually every possible market, we also must be able to process and send the phone number in a normalized way.
Fortunately, 2 standards are leading here:
- E.164 - the international public telecommunication numbering plan
- national format - popular if only supporting customers in one market
Google came up with the library that is now an unofficial standard, that allows transitions between formats as well as data validation. In PHP it was adapted as-is and released as a standalone composer library.
Drupal Contribs such as telephone_validation and telephone_formatter modules utilize said library to perform certain operations on the user input. But the problem is - we don't have a common storage where telephone could be stored in a normalized format, similar to how numbers or dates are already handled by core. With the steady growth in the usage of said modules and surpass of 10k installation I feel it's time to have better support directly in Core.
Proposed resolution
- Create a new field type plugin in the telephone module - TelephoneE164Item (telephone_e164). Allow users to choose that field type over current, simplified TelephoneItem
- Store the phone number user input AND E164 version in the database
- Create a validation constraint that will only accept the value IF user input can be represented in E164 format
- Create a formatter(s?) to show the value directly from user input, in E164 format, international or national format.
Remaining tasks
- Find out what should be the schema for the new field
- Document when the old field type should be used over the new field type (alarm numbers, vanity phone numbers, etc.
User interface changes
n/a
Introduced terminology
n/a
API changes
n/a
Data model changes
n/a
Release notes snippet
Issue fork telephone-3482705
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
quietone commentedChanges are made on on 11.x (our main development branch) first, and are then back ported as needed according to our policies.
Comment #3
quietone commentedComment #5
smustgrave commentedSo I'm not sure this will land in core as it adds additional dependencies to core to maintain.
Also there is #3266465: [policy, no patch] Remove Telephone module from core where I'm proposing telephone be removed because as you mentioned it's just a text field.
In the mean time I created https://www.drupal.org/project/telephone_e164 and if the day comes telephone gets deprecated we can move that into the contrib module.
Know it's probably not the answer you were hoping for but seem like a good compromise?
Comment #6
smustgrave commentedI opted the module into security coverage and posted #3585817: Reference new telephone_e164 module so maybe it can get some attention. If telephone ever gets deprecated I'll plan to fold the two together but think this is a good alternative.
Comment #8
zaporylieI see this information on #3266465: [policy, no patch] Remove Telephone module from core but no reference for that conversation here or anywhere else. Any chance anyone could share that reference for posterity?
Comment #9
smustgrave commentedIt was a private core channel. Think this one should remain closed as I highly doubt it landing in core with recipes now a thing.
Comment #10
smustgrave commentedTelephone has been deprecated so moving this issue to the contrib space
Comment #11
smustgrave commentedStarted a development branch
Comment #13
smustgrave commentedComment #15
smustgrave commentedLets go ahead and land this one so we can get an alpha1 out this week :)