From f0a7a0c9f7d548dba0c22c87ea6f8c0f20507419 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 17 Feb 2014 18:31:13 +1300 Subject: [PATCH] CRM-14235 Preparation for Drupal 8 fix permission hook class --- CRM/Utils/Hook.php | 20 ++++--- CRM/Utils/Hook/Drupal.php | 76 +----------------------- CRM/Utils/Hook/Drupal6.php | 61 +------------------- CRM/Utils/Hook/DrupalBase.php | 105 ++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 144 deletions(-) create mode 100644 CRM/Utils/Hook/DrupalBase.php diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index facdd3a0f2..c2c07a1ab6 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -90,14 +90,16 @@ abstract class CRM_Utils_Hook { } /** - * @param int $numParams - * @param mixed $arg1 - * @param mixed $arg2 - * @param mixed $arg3 - * @param mixed $arg4 - * @param mixed $arg5 - * @param mixed $arg6 - * @param mixed $fnSuffix + *Invoke hooks + * + * @param int $numParams Number of parameters to pass to the hook + * @param mixed $arg1 parameter to be passed to the hook + * @param mixed $arg2 parameter to be passed to the hook + * @param mixed $arg3 parameter to be passed to the hook + * @param mixed $arg4 parameter to be passed to the hook + * @param mixed $arg5 parameter to be passed to the hook + * @param mixed $arg6 parameter to be passed to the hook + * @param string $fnSuffix function suffix, this is effectively the hook name * * @return mixed */ @@ -197,7 +199,7 @@ abstract class CRM_Utils_Hook { case 6: $fResult = $fnName($arg1, $arg2, $arg3, $arg4, $arg5, $arg6); break; - + default: CRM_Core_Error::fatal(ts('Invalid hook invocation')); break; diff --git a/CRM/Utils/Hook/Drupal.php b/CRM/Utils/Hook/Drupal.php index 5b3e169cfd..f4379ff9e1 100644 --- a/CRM/Utils/Hook/Drupal.php +++ b/CRM/Utils/Hook/Drupal.php @@ -33,80 +33,6 @@ * $Id: $ * */ -class CRM_Utils_Hook_Drupal extends CRM_Utils_Hook { - - /** - * @var bool - */ - private $isBuilt = FALSE; - - /** - * @var array(string) - */ - private $allModules = NULL; - - /** - * @var array(string) - */ - private $civiModules = NULL; - - /** - * @var array(string) - */ - private $drupalModules = NULL; - - function invoke($numParams, - &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, - $fnSuffix - ) { - - $this->buildModuleList(); - - return $this->runHooks($this->allModules, $fnSuffix, - $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6 - ); - } - - /** - * Build the list of modules to be processed for hooks. - */ - function buildModuleList() { - if ($this->isBuilt === FALSE) { - if ($this->drupalModules === NULL) { - if (function_exists('module_list')) { - // copied from user_module_invoke - $this->drupalModules = module_list(); - } - } - - if ($this->civiModules === NULL) { - $this->civiModules = array(); - $this->requireCiviModules($this->civiModules); - } - - // we should add civicrm's module's just after main civicrm drupal module - // Note: Assume that drupalModules and civiModules may each be array() or NULL - if ($this->drupalModules !== NULL) { - foreach ($this->drupalModules as $moduleName) { - $this->allModules[$moduleName] = $moduleName; - if ($moduleName == 'civicrm') { - if (!empty($this->civiModules)) { - foreach ($this->civiModules as $civiModuleName) { - $this->allModules[$civiModuleName] = $civiModuleName; - } - } - } - } - } - else { - $this->allModules = (array) $this->civiModules; - } - - if ($this->drupalModules !== NULL && $this->civiModules !== NULL) { - // both CRM and CMS have bootstrapped, so this is the final list - $this->isBuilt = TRUE; - } - } - } +class CRM_Utils_Hook_Drupal extends CRM_Utils_Hook_DrupalBase { } diff --git a/CRM/Utils/Hook/Drupal6.php b/CRM/Utils/Hook/Drupal6.php index 7cde491c40..1d6a0479d4 100644 --- a/CRM/Utils/Hook/Drupal6.php +++ b/CRM/Utils/Hook/Drupal6.php @@ -32,65 +32,6 @@ * $Id: $ * */ -class CRM_Utils_Hook_Drupal6 extends CRM_Utils_Hook { - - /** - * @var bool - */ - private $isBuilt = FALSE; - - /** - * @var array(string) - */ - private $allModules = NULL; - - /** - * @var array(string) - */ - private $civiModules = NULL; - - /** - * @var array(string) - */ - private $drupalModules = NULL; - - function invoke($numParams, - &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, - $fnSuffix - ) { - - $this->buildModuleList(); - - return $this->runHooks($this->allModules, $fnSuffix, - $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6 - ); - } - - /** - * Build the list of modules to be processed for hooks. - */ - function buildModuleList() { - if ($this->isBuilt === FALSE) { - if ($this->drupalModules === NULL) { - if (function_exists('module_list')) { - // copied from user_module_invoke - $this->drupalModules = module_list(); - } - } - - if ($this->civiModules === NULL) { - $this->civiModules = array(); - $this->requireCiviModules($this->civiModules); - } - - $this->allModules = array_merge((array)$this->drupalModules, (array)$this->civiModules); - if ($this->drupalModules !== NULL && $this->civiModules !== NULL) { - // both CRM and CMS have bootstrapped, so this is the final list - $this->isBuilt = TRUE; - } - } - } +class CRM_Utils_Hook_Drupal6 extends CRM_Utils_Hook_DrupalBase { } - - diff --git a/CRM/Utils/Hook/DrupalBase.php b/CRM/Utils/Hook/DrupalBase.php new file mode 100644 index 0000000000..15fe9f247a --- /dev/null +++ b/CRM/Utils/Hook/DrupalBase.php @@ -0,0 +1,105 @@ + + * + */ + function invoke($numParams, + &$arg1, &$arg2, &$arg3, &$arg4, &$arg5, &$arg6, + $fnSuffix) { + + $this->buildModuleList(); + + return $this->runHooks($this->allModules, $fnSuffix, + $numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $arg6 + ); + } + + /** + * Build the list of modules to be processed for hooks. + */ + function buildModuleList() { + if ($this->isBuilt === FALSE) { + if ($this->drupalModules === NULL) { + if (function_exists('module_list')) { + // copied from user_module_invoke + $this->drupalModules = module_list(); + } + } + + if ($this->civiModules === NULL) { + $this->civiModules = array(); + $this->requireCiviModules($this->civiModules); + } + + $this->allModules = array_merge((array)$this->drupalModules, (array)$this->civiModules); + if ($this->drupalModules !== NULL && $this->civiModules !== NULL) { + // both CRM and CMS have bootstrapped, so this is the final list + $this->isBuilt = TRUE; + } + } + } +} \ No newline at end of file -- 2.25.1