Commit | Line | Data |
---|---|---|
f0a7a0c9 EM |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
f0a7a0c9 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
f0a7a0c9 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
f0a7a0c9 EM |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
f0a7a0c9 EM |
16 | */ |
17 | class CRM_Utils_Hook_DrupalBase extends CRM_Utils_Hook { | |
18 | ||
19 | /** | |
20 | * @var bool | |
21 | */ | |
22 | private $isBuilt = FALSE; | |
23 | ||
24 | /** | |
041ecc95 | 25 | * All Modules. |
26 | * | |
27 | * @var string[] | |
f0a7a0c9 EM |
28 | */ |
29 | private $allModules = NULL; | |
30 | ||
31 | /** | |
041ecc95 | 32 | * CiviCRM Modules. |
33 | * | |
34 | * @var string[] | |
f0a7a0c9 EM |
35 | */ |
36 | private $civiModules = NULL; | |
37 | ||
38 | /** | |
041ecc95 | 39 | * Drupal modules. |
40 | * | |
41 | * @var string[] | |
f0a7a0c9 EM |
42 | */ |
43 | private $drupalModules = NULL; | |
44 | ||
45 | /** | |
77855840 TO |
46 | * @param int $numParams |
47 | * Number of parameters to pass to the hook. | |
041ecc95 | 48 | * @param mixed $arg1 |
77855840 | 49 | * Parameter to be passed to the hook. |
041ecc95 | 50 | * @param mixed $arg2 |
77855840 | 51 | * Parameter to be passed to the hook. |
041ecc95 | 52 | * @param mixed $arg3 |
77855840 | 53 | * Parameter to be passed to the hook. |
041ecc95 | 54 | * @param mixed $arg4 |
77855840 | 55 | * Parameter to be passed to the hook. |
041ecc95 | 56 | * @param mixed $arg5 |
77855840 | 57 | * Parameter to be passed to the hook. |
77b97be7 | 58 | * @param mixed $arg6 |
77855840 TO |
59 | * @param string $fnSuffix |
60 | * Function suffix, this is effectively the hook name. | |
77b97be7 | 61 | * |
4a2db77c | 62 | * @return array|bool |
041ecc95 | 63 | * @throws \Exception |
64 | * @see CRM_Utils_Hook::invoke() | |
f0a7a0c9 | 65 | */ |
354345c9 | 66 | public function invokeViaUF( |
a3e55d9c | 67 | $numParams, |
f0a7a0c9 EM |
68 | &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, |
69 | $fnSuffix) { | |
70 | ||
71 | $this->buildModuleList(); | |
72 | ||
73 | return $this->runHooks($this->allModules, $fnSuffix, | |
74 | $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6 | |
75 | ); | |
76 | } | |
77 | ||
78 | /** | |
79 | * Build the list of modules to be processed for hooks. | |
80 | */ | |
00be9182 | 81 | public function buildModuleList() { |
f0a7a0c9 EM |
82 | if ($this->isBuilt === FALSE) { |
83 | if ($this->drupalModules === NULL) { | |
3f57d516 | 84 | $this->drupalModules = $this->getDrupalModules(); |
f0a7a0c9 EM |
85 | } |
86 | ||
87 | if ($this->civiModules === NULL) { | |
be2fb01f | 88 | $this->civiModules = []; |
f0a7a0c9 EM |
89 | $this->requireCiviModules($this->civiModules); |
90 | } | |
91 | ||
1a058091 KM |
92 | // CRM-12370 |
93 | // we should add civicrm's module's just after main civicrm drupal module | |
94 | // Note: Assume that drupalModules and civiModules may each be array() or NULL | |
95 | if ($this->drupalModules !== NULL) { | |
96 | foreach ($this->drupalModules as $moduleName) { | |
97 | $this->allModules[$moduleName] = $moduleName; | |
98 | if ($moduleName == 'civicrm') { | |
99 | if (!empty($this->civiModules)) { | |
100 | foreach ($this->civiModules as $civiModuleName) { | |
101 | $this->allModules[$civiModuleName] = $civiModuleName; | |
102 | } | |
103 | } | |
104 | } | |
105 | } | |
106 | } | |
107 | else { | |
108 | $this->allModules = (array) $this->civiModules; | |
109 | } | |
110 | ||
f0a7a0c9 EM |
111 | if ($this->drupalModules !== NULL && $this->civiModules !== NULL) { |
112 | // both CRM and CMS have bootstrapped, so this is the final list | |
113 | $this->isBuilt = TRUE; | |
114 | } | |
115 | } | |
116 | } | |
96025800 | 117 | |
3f57d516 WL |
118 | /** |
119 | * Gets modules installed on the Drupal site. | |
120 | * | |
121 | * @return array|null | |
122 | * The machine names of the modules installed in Drupal, or NULL if unable | |
123 | * to determine the modules. | |
124 | */ | |
125 | protected function getDrupalModules() { | |
126 | if (function_exists('module_list')) { | |
127 | // copied from user_module_invoke | |
128 | return module_list(); | |
129 | } | |
130 | } | |
131 | ||
77b97be7 | 132 | } |