From 5270c026a232767cc718192686dbe03a6eea1db3 Mon Sep 17 00:00:00 2001 From: Xavier Dutoit Date: Thu, 22 Aug 2013 19:16:16 +0200 Subject: [PATCH] CRM-13261 new apiwrapper hook --- CRM/Utils/Hook.php | 14 ++++++++++++++ api/api.php | 15 +++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index 94fe5eeda8..c1552bb091 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -1215,6 +1215,20 @@ abstract class CRM_Utils_Hook { ); } + /** + * This hook is called before running an api call. + * + * @param $wrappers array of implements API_Wrapper(see CRM/Utils/API/ReloadOption.php as an example) + * + * @return null the return value is ignored + * @access public + */ + static function apiWrappers (&$wrappers,$apiRequest) { + return self::singleton()->invoke(2, $wrappers, $apiRequest, self::$_nullObject, self::$_nullObject, self::$_nullObject, + 'civicrm_apiWrapper' + ); + } + /** * This hook is called before running pending cron jobs. * diff --git a/api/api.php b/api/api.php index 2564b1898b..f42d5ac8da 100644 --- a/api/api.php +++ b/api/api.php @@ -19,11 +19,20 @@ * array to be passed to function */ function civicrm_api($entity, $action, $params, $extra = NULL) { + $apiRequest = array(); + $apiRequest['entity'] = CRM_Utils_String::munge($entity); + $apiRequest['action'] = CRM_Utils_String::munge($action); + $apiRequest['version'] = civicrm_get_api_version($params); + $apiRequest['params'] = $params; + $apiRequest['extra'] = $extra; + $apiWrappers = array( CRM_Utils_API_HTMLInputCoder::singleton(), CRM_Utils_API_NullOutputCoder::singleton(), CRM_Utils_API_ReloadOption::singleton(), ); + CRM_Utils_Hook::apiWrappers($apiWrappers,$apiRequest); + try { require_once ('api/v3/utils.php'); require_once 'api/Exception.php'; @@ -32,12 +41,6 @@ function civicrm_api($entity, $action, $params, $extra = NULL) { } _civicrm_api3_initialize(); $errorScope = CRM_Core_TemporaryErrorScope::useException(); - $apiRequest = array(); - $apiRequest['entity'] = CRM_Utils_String::munge($entity); - $apiRequest['action'] = CRM_Utils_String::munge($action); - $apiRequest['version'] = civicrm_get_api_version($params); - $apiRequest['params'] = $params; - $apiRequest['extra'] = $extra; // look up function, file, is_generic $apiRequest += _civicrm_api_resolve($apiRequest); if (strtolower($action) == 'create' || strtolower($action) == 'delete') { -- 2.25.1