1

I'm trying to do a little statistics on nodes and display it on a block. I utilized menu_get_object('node', 1, $path) to get the node object of those nodes with the properties that I want.

So my problem is, in admin accounts, this works fine and well. however, in a normal user account, menu_get_object('node', 1, $path) returns null for any node that the normal user has no access to. is there any way to circumvent this?

So far I've tried using node_load(), and I also tried putting all the data analysis code inside a hook_cron(). Neither worked.

Using db_query() is not an easy task either, as I'm trying to obtain the node's parent node,and that parent's node parent node. That data is serialized. If it matters, I'm using Open Atrium, and I'm trying to obtain the topmost Space for a particular node.

1

What you can do is impersonate another user for a while. More details here https://www.drupal.org/node/218104

At the start of the function:

$session_prev_status = drupal_save_session(); 
drupal_save_session(FALSE);
global $user;
$actual_user = $user;
$impersonated_user = user_load(1); // This will impersonate user 1, an administrator.
$user = $impersonated_user;

Then, at the end of the function:

$user = $actual_user;
drupal_save_session($session_prev_status);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.