65f148358cd8d9689d857fb06635918d21544a0e
[civicrm-core.git] / CRM / Utils / Hook / Drupal.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 *
31 * @package CiviCRM_Hook
32 * @copyright CiviCRM LLC (c) 2004-2013
33 * $Id: $
34 *
35 */
36 class CRM_Utils_Hook_Drupal extends CRM_Utils_Hook {
37
38 /**
39 * @var bool
40 */
41 private $isBuilt = FALSE;
42
43 /**
44 * @var array(string)
45 */
46 private $allModules = NULL;
47
48 /**
49 * @var array(string)
50 */
51 private $civiModules = NULL;
52
53 /**
54 * @var array(string)
55 */
56 private $drupalModules = NULL;
57
58 function invoke($numParams,
59 &$arg1, &$arg2, &$arg3, &$arg4, &$arg5,
60 $fnSuffix
61 ) {
62
63 $this->buildModuleList();
64
65 return $this->runHooks($this->allModules, $fnSuffix,
66 $numParams, $arg1, $arg2, $arg3, $arg4, $arg5
67 );
68 }
69
70 /**
71 * Build the list of modules to be processed for hooks.
72 */
73 function buildModuleList() {
74 if ($this->isBuilt === FALSE) {
75 if ($this->drupalModules === NULL) {
76 if (function_exists('module_list')) {
77 // copied from user_module_invoke
78 $this->drupalModules = module_list();
79 }
80 }
81
82 if ($this->civiModules === NULL) {
83 $this->civiModules = array();
84 $this->requireCiviModules($this->civiModules);
85 }
86
87 // we should add civicrm's module's just after main civicrm drupal module
88 // Note: Assume that drupalModules and civiModules may each be array() or NULL
89 if ($this->drupalModules !== NULL) {
90 foreach ($this->drupalModules as $moduleName) {
91 $this->allModules[$moduleName] = $moduleName;
92 if ($moduleName == 'civicrm') {
93 if (!empty($this->civiModules)) {
94 foreach ($this->civiModules as $civiModuleName) {
95 $this->allModules[$civiModuleName] = $civiModuleName;
96 }
97 }
98 }
99 }
100 }
101 else {
102 $this->allModules = (array) $this->civiModules;
103 }
104
105 if ($this->drupalModules !== NULL && $this->civiModules !== NULL) {
106 // both CRM and CMS have bootstrapped, so this is the final list
107 $this->isBuilt = TRUE;
108 }
109 }
110 }
111
112 }