3 require_once 'oauth_client.civix.php';
5 use CRM_OauthClient_ExtensionUtil
as E
;
9 * Implements hook_civicrm_config().
11 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
13 function oauth_client_civicrm_config(&$config) {
14 _oauth_client_civix_civicrm_config($config);
18 * Implements hook_civicrm_xmlMenu().
20 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
22 function oauth_client_civicrm_xmlMenu(&$files) {
23 _oauth_client_civix_civicrm_xmlMenu($files);
27 * Implements hook_civicrm_managed().
29 * Generate a list of entities to create/deactivate/delete when this module
30 * is installed, disabled, uninstalled.
32 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
34 function oauth_client_civicrm_managed(&$entities) {
35 _oauth_client_civix_civicrm_managed($entities);
39 * Implements hook_civicrm_permission().
41 * @see CRM_Utils_Hook::permission()
42 * @see CRM_Core_Permission::getCorePermissions()
44 function oauth_client_civicrm_permission(&$permissions) {
45 $prefix = ts('CiviCRM') . ': ';
46 $permissions['manage OAuth client'] = [
47 $prefix . ts('manage OAuth client'),
48 ts('Create and delete OAuth client connections'),
50 $permissions['manage OAuth client secrets'] = [
51 $prefix . ts('manage OAuth client secrets'),
52 ts('Access OAuth secrets'),
54 $permissions['create OAuth tokens via auth code flow'] = [
55 $prefix . ts('create OAuth tokens via auth code flow'),
56 ts('Create OAuth tokens via the authorization code flow'),
58 $permissions['manage my OAuth contact tokens'] = [
59 $prefix . ts('manage my OAuth contact tokens'),
60 ts("Manage user's own OAuth tokens"),
62 $permissions['manage all OAuth contact tokens'] = [
63 $prefix . ts('manage all OAuth contact tokens'),
64 ts("Manage OAuth tokens for all contacts"),
69 * Implements hook_civicrm_caseTypes().
71 * Generate a list of case-types.
73 * Note: This hook only runs in CiviCRM 4.4+.
75 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
77 function oauth_client_civicrm_caseTypes(&$caseTypes) {
78 _oauth_client_civix_civicrm_caseTypes($caseTypes);
82 * Implements hook_civicrm_angularModules().
84 * Generate a list of Angular modules.
86 * Note: This hook only runs in CiviCRM 4.5+. It may
87 * use features only available in v4.6+.
89 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
91 function oauth_client_civicrm_angularModules(&$angularModules) {
92 _oauth_client_civix_civicrm_angularModules($angularModules);
96 * Implements hook_civicrm_alterSettingsFolders().
98 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
100 function oauth_client_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
101 _oauth_client_civix_civicrm_alterSettingsFolders($metaDataFolders);
105 * Implements hook_civicrm_entityTypes().
107 * Declare entity types provided by this module.
109 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
111 function oauth_client_civicrm_entityTypes(&$entityTypes) {
112 _oauth_client_civix_civicrm_entityTypes($entityTypes);
116 * Implements hook_civicrm_thems().
118 function oauth_client_civicrm_themes(&$themes) {
119 _oauth_client_civix_civicrm_themes($themes);
122 // --- Functions below this ship commented out. Uncomment as required. ---
125 * Implements hook_civicrm_preProcess().
127 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
129 //function oauth_client_civicrm_preProcess($formName, &$form) {
134 * Implements hook_civicrm_navigationMenu().
136 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
138 //function oauth_client_civicrm_navigationMenu(&$menu) {
139 // _oauth_client_civix_insert_navigation_menu($menu, 'Mailings', array(
140 // 'label' => E::ts('New subliminal message'),
141 // 'name' => 'mailing_subliminal_message',
142 // 'url' => 'civicrm/mailing/subliminal',
143 // 'permission' => 'access CiviMail',
144 // 'operator' => 'OR',
147 // _oauth_client_civix_navigationMenu($menu);
151 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
153 function oauth_client_civicrm_container($container) {
154 $container->addResource(new \Symfony\Component\Config\
Resource\
FileResource(__FILE__
));
155 $container->setDefinition('oauth2.league', new \Symfony\Component\DependencyInjection\
Definition(
156 \Civi\OAuth\OAuthLeagueFacade
::class, []))->setPublic(TRUE);
157 $container->setDefinition('oauth2.token', new \Symfony\Component\DependencyInjection\
Definition(
158 \Civi\OAuth\OAuthTokenFacade
::class, []))->setPublic(TRUE);
162 * Implements hook_civicrm_oauthProviders().
164 function oauth_client_civicrm_oauthProviders(&$providers) {
165 $ingest = function($pat) use (&$providers) {
166 $files = (array) glob($pat);
167 foreach ($files as $file) {
168 if (!defined('CIVICRM_TEST') && preg_match(';\.test\.json$;', $file)) {
171 $name = preg_replace(';\.(dist\.|test\.|)json$;', '', basename($file));
172 $provider = json_decode(file_get_contents($file), 1);
173 $provider['name'] = $name;
174 $providers[$name] = $provider;
178 $ingest(__DIR__
. '/providers/*.json');
179 $localDir = Civi
::paths()->getPath('[civicrm.private]/oauth-providers');
180 if (file_exists($localDir)) {
181 $ingest($localDir . '/*.json');
186 * Implements hook_civicrm_mailSetupActions().
188 * @see CRM_Utils_Hook::mailSetupActions()
190 function oauth_client_civicrm_mailSetupActions(&$setupActions) {
191 $setupActions = array_merge($setupActions, CRM_OAuth_MailSetup
::buildSetupLinks());
195 * Implements hook_civicrm_oauthReturn().
197 function oauth_client_civicrm_oauthReturn($token, &$nextUrl) {
198 CRM_OAuth_MailSetup
::onReturn($token, $nextUrl);
202 * Implements hook_civicrm_alterMailStore().
204 * @see CRM_Utils_Hook::alterMailStore()
206 function oauth_client_civicrm_alterMailStore(&$mailSettings) {
207 CRM_OAuth_MailSetup
::alterMailStore($mailSettings);