-
Notifications
You must be signed in to change notification settings - Fork 1
/
cmsuser.php
executable file
·162 lines (153 loc) · 4.72 KB
/
cmsuser.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
require_once 'cmsuser.civix.php';
/**
* Implementation of hook_civicrm_config
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_config
*/
function cmsuser_civicrm_config(&$config) {
_cmsuser_civix_civicrm_config($config);
}
/**
* Implementation of hook_civicrm_install
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install
*/
function cmsuser_civicrm_install() {
checkCMS();
_cmsuser_civix_civicrm_install();
}
/**
* Implementation of hook_civicrm_enable
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable
*/
function cmsuser_civicrm_enable() {
_cmsuser_civix_civicrm_enable();
}
/**
* Function to ensure extension is used only in Drupal.
*
*/
function checkCMS() {
if (CRM_Core_Config::singleton()->userFramework == "Joomla") {
CRM_Core_Error::fatal(ts("This extension currently does not support Joomla CMS."));
}
}
/**
* Implementation of hook_civicrm_pre
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pre
*/
function cmsuser_civicrm_pre($op, $objectName, $id, &$params) {
if ($op == "create" && $objectName == "Profile" && ($cid = CRM_Utils_Request::retrieve('crmId', 'Integer'))) {
$cms = CRM_Core_Config::singleton()->userFramework;
switch ($cms) {
case "Drupal":
// Set contact ID so that new contact is not created by CiviCRM.
$params['contact_id'] = $cid;
break;
case "WordPress":
// FIXME
case "Joomla":
// FIXME
break;
default:
break;
}
}
}
/**
* Implementation of hook_civicrm_pageRun
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pageRun
*/
function cmsuser_civicrm_pageRun(&$page) {
if ($page->getVar('_name') == "CRM_Contact_Page_View_Summary") {
$cms = CRM_Core_Config::singleton()->userFramework;
switch ($cms) {
case "Drupal":
case 'Drupal8':
$cid = CRM_Core_Session::singleton()->get('view.id');
$uid = CRM_Core_BAO_UFMatch::getUFId($cid);
if ($uid) {
$userRecordUrl = CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($cid);
if ($cms == 'Drupal8') {
$username = \Drupal\user\Entity\User::load($uid)->getAccountName();
}
else {
$username = user_load($uid)->name;
}
$page->assign('cmsUser', $username);
}
else {
$userRecordUrl = CRM_Utils_System::url("admin/people/create", array('crmId' => $cid));
$page->assign('cmsUser', "Create User");
}
$page->assign('cmsURL', $userRecordUrl);
CRM_Core_Region::instance('page-body')->add(array(
'template' => 'CMSUser.tpl',
));
break;
case "WordPress":
$cid = CRM_Core_Session::singleton()->get('view.id');
$uid = CRM_Core_BAO_UFMatch::getUFId($cid);
if ($uid) {
$userRecordUrl = CRM_Core_Config::singleton()->userSystem->getUserRecordUrl($cid);
$user = get_userdata($uid);
$username = $user->data->display_name;
$page->assign('cmsUser', $username);
}
else {
$userRecordUrl = CRM_Utils_System::url("civicrm/contact/view/useradd", array('cid' => $cid, 'reset' => 1, 'action' => 'add'));
$page->assign('cmsUser', "Create User");
}
$page->assign('cmsURL', $userRecordUrl);
CRM_Core_Region::instance('page-body')->add(array(
'template' => 'CMSUser.tpl',
));
break;
case "Joomla":
// FIXME
break;
default:
break;
}
}
}
/**
* Implementation of hook_civicrm_buildForm
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm
*/
function cmsuser_civicrm_buildForm($formName, &$form) {
if ($formName == "CRM_Profile_Form_Dynamic" && ($cid = CRM_Utils_Request::retrieve('crmId', 'Integer'))) {
$cms = CRM_Core_Config::singleton()->userFramework;
switch ($cms) {
case "Drupal":
case "Drupal8":
$result = civicrm_api3('Contact', 'get', array(
'sequential' => 1,
'return' => "first_name,last_name,email",
'id' => $cid,
));
if ($result['count'] > 0) {
$defaults = array(
'first_name' => $result['values'][0]['first_name'],
'last_name' => $result['values'][0]['last_name'],
);
$form->setDefaults($defaults);
}
$url = CRM_Core_Config::singleton()->extensionsURL . DIRECTORY_SEPARATOR . basename(__DIR__) . "/templates/res/js/cms.js";
drupal_add_js($url, 'external');
break;
case "WordPress":
// FIXME
case "Joomla":
// FIXME
break;
default:
break;
}
}
}