Skip to content

Instantly share code, notes, and snippets.

@totten
Created January 5, 2016 00:48
Show Gist options
  • Save totten/f3288da69b06fc0d10c3 to your computer and use it in GitHub Desktop.
Save totten/f3288da69b06fc0d10c3 to your computer and use it in GitHub Desktop.
diff --git a/Civi/API/Kernel.php b/Civi/API/Kernel.php
index 9d85508..85c5976 100644
--- a/Civi/API/Kernel.php
+++ b/Civi/API/Kernel.php
@@ -50,6 +50,12 @@ class Kernel {
protected $apiProviders;
/**
+ * @var array
+ * Stack of pending API requests.
+ */
+ protected $requests;
+
+ /**
* @param \Symfony\Component\EventDispatcher\EventDispatcher $dispatcher
* The event dispatcher which receives kernel events.
* @param array $apiProviders
@@ -58,6 +64,7 @@ class Kernel {
public function __construct($dispatcher, $apiProviders = array()) {
$this->apiProviders = $apiProviders;
$this->dispatcher = $dispatcher;
+ $this->requests = array();
}
/**
@@ -81,6 +88,7 @@ class Kernel {
// TODO Define alternative calling convention makes it easier to construct $apiRequest
// without the ambiguity of "data" vs "options"
$apiRequest = Request::create($entity, $action, $params, $extra);
+ array_unshift($this->requests, $apiRequest);
try {
if (!is_array($params)) {
@@ -96,7 +104,9 @@ class Kernel {
$result = $apiProvider->invoke($apiRequest);
$apiResponse = $this->respond($apiProvider, $apiRequest, $result);
- return $this->formatResult($apiRequest, $apiResponse);
+ $formatResult = $this->formatResult($apiRequest, $apiResponse);
+ array_shift($this->requests);
+ return $formatResult;
}
catch (\Exception $e) {
$this->dispatcher->dispatch(Events::EXCEPTION, new ExceptionEvent($e, $apiProvider, $apiRequest, $this));
@@ -111,7 +121,9 @@ class Kernel {
$err = $this->formatException($e, $apiRequest);
}
- return $this->formatResult($apiRequest, $err);
+ $formatResult = $this->formatResult($apiRequest, $err);
+ array_shift($this->requests);
+ return $formatResult;
}
}
@@ -433,4 +445,13 @@ class Kernel {
return $this;
}
+ /**
+ * Get the currently active API request.
+ *
+ * @return array|NULL
+ */
+ public function getActiveRequest() {
+ return isset($this->requests[0]) ? $this->requests[0] : NULL;
+ }
+
}
diff --git a/api/v3/utils.php b/api/v3/utils.php
index 3e7d31f..16ed3c9 100644
--- a/api/v3/utils.php
+++ b/api/v3/utils.php
@@ -740,7 +740,7 @@ function _civicrm_api3_get_using_utils_sql($dao_name, $params, $isFillUniqueFiel
}
$result_entities = array();
- CRM_Utils_Hook::entityGet($entity, $query, !empty($params['check_permissions']));
+ CRM_Utils_Hook::entityGet(Civi::service('civi_api_kernel')->getActiveRequest(), $query);
$result_dao = CRM_Core_DAO::executeQuery($query->toSQL());
while ($result_dao->fetch()) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment