dev/core#2141 - Allow OAuth2 services to define mail setup routine
[civicrm-core.git] / ext / oauth-client / oauth_client.php
CommitLineData
ed463944
TO
1<?php
2
3require_once 'oauth_client.civix.php';
4// phpcs:disable
5use CRM_OauthClient_ExtensionUtil as E;
6// phpcs:enable
7
8/**
9 * Implements hook_civicrm_config().
10 *
11 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_config/
12 */
13function oauth_client_civicrm_config(&$config) {
14 _oauth_client_civix_civicrm_config($config);
15}
16
17/**
18 * Implements hook_civicrm_xmlMenu().
19 *
20 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_xmlMenu
21 */
22function oauth_client_civicrm_xmlMenu(&$files) {
23 _oauth_client_civix_civicrm_xmlMenu($files);
24}
25
26/**
27 * Implements hook_civicrm_install().
28 *
29 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install
30 */
31function oauth_client_civicrm_install() {
32 _oauth_client_civix_civicrm_install();
33}
34
35/**
36 * Implements hook_civicrm_postInstall().
37 *
38 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall
39 */
40function oauth_client_civicrm_postInstall() {
41 _oauth_client_civix_civicrm_postInstall();
42}
43
44/**
45 * Implements hook_civicrm_uninstall().
46 *
47 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall
48 */
49function oauth_client_civicrm_uninstall() {
50 _oauth_client_civix_civicrm_uninstall();
51}
52
53/**
54 * Implements hook_civicrm_enable().
55 *
56 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable
57 */
58function oauth_client_civicrm_enable() {
59 _oauth_client_civix_civicrm_enable();
60}
61
62/**
63 * Implements hook_civicrm_disable().
64 *
65 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable
66 */
67function oauth_client_civicrm_disable() {
68 _oauth_client_civix_civicrm_disable();
69}
70
71/**
72 * Implements hook_civicrm_upgrade().
73 *
74 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_upgrade
75 */
76function oauth_client_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
77 return _oauth_client_civix_civicrm_upgrade($op, $queue);
78}
79
80/**
81 * Implements hook_civicrm_managed().
82 *
83 * Generate a list of entities to create/deactivate/delete when this module
84 * is installed, disabled, uninstalled.
85 *
86 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_managed
87 */
88function oauth_client_civicrm_managed(&$entities) {
89 _oauth_client_civix_civicrm_managed($entities);
90}
91
9959dad1
TO
92/**
93 * Implements hook_civicrm_permission().
94 *
95 * @see CRM_Utils_Hook::permission()
96 * @see CRM_Core_Permission::getCorePermissions()
97 */
98function oauth_client_civicrm_permission(&$permissions) {
99 $prefix = ts('CiviCRM') . ': ';
100 $permissions['manage OAuth client'] = [
101 $prefix . ts('manage OAuth client'),
102 ts('Create and delete OAuth client connections'),
103 ];
104 $permissions['manage OAuth client secrets'] = [
105 $prefix . ts('manage OAuth client secrets'),
106 ts('Access OAuth secrets'),
107 ];
108}
109
ed463944
TO
110/**
111 * Implements hook_civicrm_caseTypes().
112 *
113 * Generate a list of case-types.
114 *
115 * Note: This hook only runs in CiviCRM 4.4+.
116 *
117 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_caseTypes
118 */
119function oauth_client_civicrm_caseTypes(&$caseTypes) {
120 _oauth_client_civix_civicrm_caseTypes($caseTypes);
121}
122
123/**
124 * Implements hook_civicrm_angularModules().
125 *
126 * Generate a list of Angular modules.
127 *
128 * Note: This hook only runs in CiviCRM 4.5+. It may
129 * use features only available in v4.6+.
130 *
131 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_angularModules
132 */
133function oauth_client_civicrm_angularModules(&$angularModules) {
134 _oauth_client_civix_civicrm_angularModules($angularModules);
135}
136
137/**
138 * Implements hook_civicrm_alterSettingsFolders().
139 *
140 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterSettingsFolders
141 */
142function oauth_client_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
143 _oauth_client_civix_civicrm_alterSettingsFolders($metaDataFolders);
144}
145
146/**
147 * Implements hook_civicrm_entityTypes().
148 *
149 * Declare entity types provided by this module.
150 *
151 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_entityTypes
152 */
153function oauth_client_civicrm_entityTypes(&$entityTypes) {
154 _oauth_client_civix_civicrm_entityTypes($entityTypes);
155}
156
157/**
158 * Implements hook_civicrm_thems().
159 */
160function oauth_client_civicrm_themes(&$themes) {
161 _oauth_client_civix_civicrm_themes($themes);
162}
163
164// --- Functions below this ship commented out. Uncomment as required. ---
165
166/**
167 * Implements hook_civicrm_preProcess().
168 *
169 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_preProcess
170 */
171//function oauth_client_civicrm_preProcess($formName, &$form) {
172//
173//}
174
175/**
176 * Implements hook_civicrm_navigationMenu().
177 *
178 * @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_navigationMenu
179 */
180//function oauth_client_civicrm_navigationMenu(&$menu) {
181// _oauth_client_civix_insert_navigation_menu($menu, 'Mailings', array(
182// 'label' => E::ts('New subliminal message'),
183// 'name' => 'mailing_subliminal_message',
184// 'url' => 'civicrm/mailing/subliminal',
185// 'permission' => 'access CiviMail',
186// 'operator' => 'OR',
187// 'separator' => 0,
188// ));
189// _oauth_client_civix_navigationMenu($menu);
190//}
3ee128fb 191
a17b2d8a
TO
192/**
193 * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
194 */
195function oauth_client_civicrm_container($container) {
196 $container->addResource(new \Symfony\Component\Config\Resource\FileResource(__FILE__));
197 $container->setDefinition('oauth2.league', new \Symfony\Component\DependencyInjection\Definition(
198 \Civi\OAuth\OAuthLeagueFacade::class, []))->setPublic(TRUE);
199 $container->setDefinition('oauth2.token', new \Symfony\Component\DependencyInjection\Definition(
200 \Civi\OAuth\OAuthTokenFacade::class, []))->setPublic(TRUE);
201}
202
3ee128fb
TO
203/**
204 * Implements hook_civicrm_oauthProviders().
205 */
206function oauth_client_civicrm_oauthProviders(&$providers) {
2752428e
TO
207 $ingest = function($pat) use (&$providers) {
208 $files = (array) glob($pat);
209 foreach ($files as $file) {
210 if (!defined('CIVICRM_TEST') && preg_match(';\.test\.json$;', $file)) {
211 continue;
212 }
213 $name = preg_replace(';\.(dist\.|test\.|)json$;', '', basename($file));
214 $provider = json_decode(file_get_contents($file), 1);
215 $provider['name'] = $name;
216 $providers[$name] = $provider;
3ee128fb
TO
217 }
218 };
219
2752428e
TO
220 $ingest(__DIR__ . '/providers/*.json');
221 $localDir = Civi::paths()->getPath('[civicrm.private]/oauth-providers');
222 if (file_exists($localDir)) {
223 $ingest($localDir . '/*.json');
3ee128fb
TO
224 }
225}
7be4bff1
TO
226
227/**
228 * Implements hook_civicrm_mailSetupActions().
229 *
230 * @see CRM_Utils_Hook::mailSetupActions()
231 */
232function oauth_client_civicrm_mailSetupActions(&$setupActions) {
233 $setupActions = array_merge($setupActions, CRM_OAuth_MailSetup::buildSetupLinks());
234}
235
236/**
237 * Implements hook_civicrm_oauthReturn().
238 */
239function oauth_client_civicrm_oauthReturn($token, &$nextUrl) {
240 CRM_OAuth_MailSetup::onReturn($token, $nextUrl);
241}