function phone_libphonenumber in Phone 7.2
Helper function to detect and/or load the libphonenumber libraries.
Parameters
bool $detect_only: When TRUE, the library will not be loaded. Its presence will only be checked for. Defaults to FALSE.
bool $mute: When TRUE, this function will not output an error message, or write to the watchdog table. Defaults to FALSE.
Return value
bool TRUE if $detect_only is FALSE and the library is loaded. TRUE if $detect_only is TRUE and the library is found. FALSE otherwise.
7 calls to phone_libphonenumber()
- phone_countries in ./
phone.module - Helper function to get a list of countries.
- phone_element_validate in includes/
phone.element.inc - An #element_validate callback for the phone element.
- phone_field_formatter_view in ./
phone.module - Implements hook_field_formatter_view().
- phone_field_presave in ./
phone.module - Implements hook_field_presave().
- phone_requirements in ./
phone.install - Implements hook_requirements().
File
- ./
phone.module, line 74 - The phone module lets administrators use a phone number field type.
Code
function phone_libphonenumber($detect_only = FALSE, $mute = FALSE) {
static $success = NULL;
if (isset($success)) {
return $success;
}
$function = 'libraries_' . ($detect_only ? 'detect' : 'load');
$library = $function('libphonenumber-for-php');
$result = $library['installed'] && ($detect_only || $library['loaded']);
if (!$result && !$mute) {
watchdog('phone', 'The libphonenumber library is not installed. There will be no validation, or formatting of phone numbers unless it is installed. Download it from <a href="!url">here</a> and install it into sites/all/libraries/libphonenumber-for-php. Once installed, you may need to re-save any existing phone field settings, and phone field data may also need updating.', array(
'!url' => $library['download url'],
), WATCHDOG_ERROR);
drupal_set_message(t('The libphonenumber library is not installed. There will be no validation, or formatting of phone numbers unless it is installed. Download it from <a href="@url">here</a> and install it into sites/all/libraries/libphonenumber-for-php. Once installed, you may need to re-save any existing phone field settings, and phone field data may also need updating.', array(
'@url' => $library['download url'],
)), 'error');
}
// Do not statically cache detection only calls; breaks unit tests.
$success = $detect_only ? NULL : $result;
return $result;
}