Skip to content

Instantly share code, notes, and snippets.

@cotto
Created September 14, 2011 20:19
Show Gist options
  • Save cotto/1217660 to your computer and use it in GitHub Desktop.
Save cotto/1217660 to your computer and use it in GitHub Desktop.
diff --git a/services.runtime.inc b/services.runtime.inc
index ec6f801..ccf90c5 100644
--- a/services.runtime.inc
+++ b/services.runtime.inc
@@ -139,6 +139,12 @@ function services_controller_execute($controller, $args = array(), $options = ar
$access_arguments = $args;
}
+ // Load the proper file for the access callback
+ if (!empty($controller['access callback file']) && $access_cb_file = $controller['access callback file']) {
+ $access_cb_file_name = isset($access_cb_file['name']) ? $access_cb_file['name'] : NULL;
+ module_load_include($access_cb_file['type'], $access_cb_file['module'], $access_cb_file_name);
+ }
+
// Call default or custom access callback
if (call_user_func_array($controller['access callback'], $access_arguments) != TRUE) {
global $user;
diff --git a/services.services.api.php b/services.services.api.php
index 031f7a4..a1393fb 100644
--- a/services.services.api.php
+++ b/services.services.api.php
@@ -41,9 +41,16 @@
* - help: Text describing what this callback does.
* - callback: The name of a function to call when this resource is
* requested.
+ * - file: an array describing the file which contains the callback
+ * function
* - access callback: The name of a function to call to check whether
* the requesting user has permission to access this resource. If not
* specified, this defaults to 'user_access'.
+ * - access callback file: an array describing the file which contains the
+ * access callback function. This attribute only needs to be supplied if
+ * the method callback and the access callback are defined in different
+ * files, for example when a method callback is overridden using
+ * hook_services_resources_alter but the access callback is not
* - access arguments: The arguments to pass to the access callback.
* - access arguments append: A boolean indicating whether the resource's
* arguments should be appended to the access arguments. This can be useful
@@ -79,6 +86,7 @@ $node_resource = array(
),
),
'access callback' => '_node_resource_access',
+ 'access callback file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
'access arguments' => array('view'),
'access arguments append' => TRUE,
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment