-
Notifications
You must be signed in to change notification settings - Fork 0
/
phonecountry.php
79 lines (71 loc) · 2.09 KB
/
phonecountry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
require_once 'phonecountry.civix.php';
use CRM_Phonecountry_ExtensionUtil as E;
/**
* Implements hook_civicrm_config().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
*/
function phonecountry_civicrm_config(&$config): void {
_phonecountry_civix_civicrm_config($config);
}
/**
* Implements hook_civicrm_install().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
*/
function phonecountry_civicrm_install(): void {
_phonecountry_civix_civicrm_install();
}
/**
* Implements hook_civicrm_enable().
*
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
*/
function phonecountry_civicrm_enable(): void {
_phonecountry_civix_civicrm_enable();
}
/**
* Implementation of hook_civicrm_pre
*/
function phonecountry_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
if ($objectName == 'Phone') {
$currentCode = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Phone', $objectId, 'country_code');
$newCode = CRM_Phonecountry_Utils::getPhoneCountryCode($objectRef->phone);
if ($newCode != $currentCode) {
CRM_Core_DAO::setFieldValue('CRM_Core_DAO_Phone', $objectId, 'country_code', $newCode);
}
}
}
/**
* Implements hook_civicrm_qType().
*/
function phonecountry_civicrm_entityTypes(&$entityTypes) {
$civiVersion = CRM_Utils_System::version();
$phone = 'CRM_Core_DAO_Phone';
if (version_compare($civiVersion, '5.75.0') >= 0) {
$phone = 'Phone';
}
$entityTypes[$phone]['fields_callback'][]
= function ($class, &$fields) {
$fields['country_code'] = [
'name' => 'country_code',
'title' => ts('Country code'),
'type' => CRM_Utils_Type::T_STRING,
'sql_type' => 'varchar(255)',
'input_type' => 'Text',
'description' => ts('Country Code.'),
'add' => '5.75',
'html' => [
'type' => 'Text',
],
'input_attrs' => [
'label' => ts('Country Code.'),
],
'where' => 'civicrm_phone.country_code',
'table_name' => 'civicrm_phone',
'entity' => 'Phone',
'bao' => 'CRM_Core_BAO_Phone',
];
};
}