xini / silverstripe-international-phone-number-field
此包已被废弃且不再维护。作者建议使用innoweb/silverstripe-international-phone-number-field包。
使用Google的libphonenumber添加电话字段。
5.1.1
2024-09-10 01:04 UTC
Requires
Replaces
README
简介
使用Google的libphonenumber和intl-tel-input插件添加国际电话号码的数据库和表单字段。
支持的IP地理定位服务
需求
- Silverstripe ^5
- libphonenumber PHP端口 ^8
注意:此版本与SilverStripe 5兼容。对于SilverStripe 4,请参阅4发布分支。
安装
使用composer安装模块
composer require innoweb/silverstripe-international-phone-number-field dev-master
然后运行dev/build。
用法
数据库字段
本模块提供用于数据对象的数据库字段
private static $db = [
...
'PhoneNumber' => 'Phone',
...
];
该字段将电话号码存储在数据库中为varchar类型。
在CMS中,数据类型Phone
以InternationalPhoneNumberField
的形式呈现。
在模板中,以下格式化函数可用
$PhoneNumber.International
:返回国际格式电话号码,例如“+41 44 668 1800”$PhoneNumber.National
:返回国家格式电话号码,例如“044 668 1800”$PhoneNumber.E164
:返回未格式化的国际格式电话号码,例如“+41446681800”$PhoneNumber.URL
或$PhoneNumber.RFC3966
:返回国际格式电话号码,但所有空格和其他分隔符号均用连字符替换,并且任何电话号码扩展均以“;ext=”附加。它还将添加“tel:”前缀,例如“tel:+41-44-668-1800”。
表单字段
InternationalPhoneNumberField
可用于任何存储电话号码的Varchar字段。
配置
要将字段设置为使用用户当前位置作为默认值并自定义字段,可以为InternationalPhoneNumberField
类配置以下选项
geolocation_service
:使用IP位置确定当前用户的country code。可以是'ipstack'
、'ipinfo'
、'ipgeolocation'
或'freegeoip'
。默认为'freegeoip'
。geolocation_api_key
:来自ipstack.com、ipinfo.io或ipgeolocation的API密钥。默认为false
。geolocation_protocol
:连接到地理位置服务时要使用的协议。默认为'https'
。initial_country
:电话号码字段中最初显示的国家代码。默认为'auto'
,在这种情况下,如果设置了地理位置,则使用地理位置确定位置。only_countries
:可供选择的国家代码数组。默认为false
,列出所有国家。preferred_countries
:应推送到下拉列表顶部的国家代码数组。默认为false
,按字母顺序列出所有国家。excluded_countries
:要排除的下拉列表中的国家代码数组。默认为false
,列出所有国家。
许可证
BSD 3-clause 许可证,请参阅许可证