+/**
+ * Filter the result.
+ *
+ * @param array $result
+ *
+ * @return array
+ * @throws \CRM_Core_Exception
+ */
+function _civicrm_api3_contact_formatResult($params, $result) {
+ $apiKeyPerms = array('edit api keys', 'administer CiviCRM');
+ $allowApiKey = empty($params['check_permissions']) || CRM_Core_Permission::check(array($apiKeyPerms));
+ if (!$allowApiKey) {
+ if (is_array($result)) {
+ // Single-value $result
+ if (isset($result['api_key'])) {
+ unset($result['api_key']);
+ }
+
+ // Multi-value $result
+ foreach ($result as $key => $row) {
+ if (is_array($row)) {
+ unset($result[$key]['api_key']);
+ }
+ }
+ }
+ }
+ return $result;
+}
+