I would like to create a hook in _node_resource_access so other modules could modify access.

Is this a feature that could be integrated into Services if a patch is provided?

Comments

monstrfolk created an issue. See original summary.

tyler.frankenstein’s picture

Category: Feature request » Support request

Use this hook to modify the resource and then you can declare your own custom access callback, which could piggy back off of the original access callback: http://cgit.drupalcode.org/services/tree/docs/services.alter.api.php?h=7...

kylebrowning’s picture

You can checkout this file, services.alter.api.php

Which conains this hook,

<?php
/**
 * Allows alteration of the services_resources array.
 *
 * @param array $resources
 *   The combined array of resource definitions from hook_services_resources.
 * @param array $endpoint
 *   An array describing the endpoint that resources are being built for.
 */
function hook_services_resources_alter(&$resources, &$endpoint) {

}
?>

That will let you change the hook access to a function you write yourself.

Hope this helps!

kylebrowning’s picture

Doh, Tyler beat me to it!

monstrfolk’s picture

Thanks for the information.

You guys are quick with help. Very nice.

kylebrowning’s picture

Status: Active » Fixed

No problem! Let us know if you have any other questions.

monstrfolk’s picture

There is a lot of extra stuff happening in the original access callback.

  // Adds backwards compatibility with regression fixed in #1083242
  if (isset($args[0])) {
    $args[0] = _services_access_value($args[0], 'node');
  }

  // Make sure we have an object or this all fails, some servers can
  // mess up the types.
  if (is_array($args[0])) {
    $args[0] = (object) $args[0];
  }
  elseif (!is_array($args[0]) && !is_object($args[0])) {
    $args[0] = (object)array('nid' => $args[0]);
  }

I think that creating a hook in the access check would be a good idea. That way modules wanting to extend access do not have to worry about ensuring the data is properly formatted.

Thoughts?

monstrfolk’s picture

To explain further...what I would like is the following.

_node_access_callback() {
  // check data is properly formatted.
  // check core access
  // check extended access from modules
  // return true or false.
}
monstrfolk’s picture

Another idea is to move the data format checking into a helper function that could be called from an extended module. I think that might work better than a hook.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.