Merge pull request #11252 from mattwire/CRM-21405_outboundsms_mobile_notprimary
[civicrm-core.git] / CRM / Utils / Hook / DrupalBase.php
CommitLineData
f0a7a0c9
EM
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
f0a7a0c9 5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
f0a7a0c9
EM
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
d25dd0ee 26 */
f0a7a0c9
EM
27
28/**
29 *
30 * @package CRM
0f03f337 31 * @copyright CiviCRM LLC (c) 2004-2017
f0a7a0c9
EM
32 */
33class CRM_Utils_Hook_DrupalBase extends CRM_Utils_Hook {
34
35 /**
36 * @var bool
37 */
38 private $isBuilt = FALSE;
39
40 /**
41 * @var array(string)
42 */
43 private $allModules = NULL;
44
45 /**
46 * @var array(string)
47 */
48 private $civiModules = NULL;
49
50 /**
51 * @var array(string)
52 */
53 private $drupalModules = NULL;
54
55 /**
77b97be7 56 * @see CRM_Utils_Hook::invoke()
f0a7a0c9 57 *
77855840
TO
58 * @param int $numParams
59 * Number of parameters to pass to the hook.
60 * @param unknown $arg1
61 * Parameter to be passed to the hook.
62 * @param unknown $arg2
63 * Parameter to be passed to the hook.
64 * @param unknown $arg3
65 * Parameter to be passed to the hook.
66 * @param unknown $arg4
67 * Parameter to be passed to the hook.
68 * @param unknown $arg5
69 * Parameter to be passed to the hook.
77b97be7 70 * @param mixed $arg6
77855840
TO
71 * @param string $fnSuffix
72 * Function suffix, this is effectively the hook name.
77b97be7 73 *
4a2db77c 74 * @return array|bool
f0a7a0c9 75 */
354345c9 76 public function invokeViaUF(
a3e55d9c 77 $numParams,
f0a7a0c9
EM
78 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6,
79 $fnSuffix) {
80
81 $this->buildModuleList();
82
83 return $this->runHooks($this->allModules, $fnSuffix,
84 $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6
85 );
86 }
87
88 /**
89 * Build the list of modules to be processed for hooks.
90 */
00be9182 91 public function buildModuleList() {
f0a7a0c9
EM
92 if ($this->isBuilt === FALSE) {
93 if ($this->drupalModules === NULL) {
3f57d516 94 $this->drupalModules = $this->getDrupalModules();
f0a7a0c9
EM
95 }
96
97 if ($this->civiModules === NULL) {
98 $this->civiModules = array();
99 $this->requireCiviModules($this->civiModules);
100 }
101
1a058091
KM
102 // CRM-12370
103 // we should add civicrm's module's just after main civicrm drupal module
104 // Note: Assume that drupalModules and civiModules may each be array() or NULL
105 if ($this->drupalModules !== NULL) {
106 foreach ($this->drupalModules as $moduleName) {
107 $this->allModules[$moduleName] = $moduleName;
108 if ($moduleName == 'civicrm') {
109 if (!empty($this->civiModules)) {
110 foreach ($this->civiModules as $civiModuleName) {
111 $this->allModules[$civiModuleName] = $civiModuleName;
112 }
113 }
114 }
115 }
116 }
117 else {
118 $this->allModules = (array) $this->civiModules;
119 }
120
f0a7a0c9
EM
121 if ($this->drupalModules !== NULL && $this->civiModules !== NULL) {
122 // both CRM and CMS have bootstrapped, so this is the final list
123 $this->isBuilt = TRUE;
124 }
125 }
126 }
96025800 127
3f57d516
WL
128 /**
129 * Gets modules installed on the Drupal site.
130 *
131 * @return array|null
132 * The machine names of the modules installed in Drupal, or NULL if unable
133 * to determine the modules.
134 */
135 protected function getDrupalModules() {
136 if (function_exists('module_list')) {
137 // copied from user_module_invoke
138 return module_list();
139 }
140 }
141
77b97be7 142}