[development] Blocks and page context

Steven Jones steven.jones at computerminds.co.uk
Sat Apr 24 06:34:14 UTC 2010

Hi Everett,

If you do go down the path of changing the global $user object, then
you will want to use session_save_session to make your code look
something like this:

// Don't save the session if the next block of code fails:
// Save the old user account someplace.

$user = user_load(0);
// Some computation....

// Something like this:
$user = $the_old_user

// Its now safe to start saving the session again:


If your 'Computation' in the middle there fails, then the users
session will be saved with the $user object you loaded up, i.e.
they'll get logged out. Annoying at the moment, but if you ever change
it to assign other users to the $user object then you might end up
with people being logged in as other people if the 'computation' fails
for some reason.

Steven Jones
ComputerMinds ltd - Perfect Drupal Websites

Phone : 024 7666 7277
Mobile : 07702 131 576
Twitter : darthsteven

On 23 April 2010 23:17, E.J. Zufelt <lists at zufelt.ca> wrote:
> Good afternoon,
> Thanks for the response.
> Would it be acceptable in the Drupal community for me to solve this problem
> by creating a user0 object, switching it with the global $user, perform the
> test, and then switch back?  By acceptable I mean are there any significant
> problems I shoud be aware of if using this approach?
> Thanks again,
> Everett Zufelt
> http://zufelt.ca
> Follow me on Twitter
> http://twitter.com/ezufelt
> View my LinkedIn Profile
> http://www.linkedin.com/in/ezufelt
> On 2010-04-23, at 6:12 PM, Jennifer Hodgdon wrote:
> E.J. Zufelt wrote:
> I notice that menu_get_item() will tell me if the current user can access
> the current menu item.  Is there a simple method to test if user0 can access
> the current menu item?  That is, regardless who the current user is, I would
> like to see if there is a function to let me know if user0 can access the
> current page, essentially a test to see if the current page is available to
> anonymous users or not.
> I don't think there's an easy way. The access checking for menu_get_item()
> is done in _menu_check_access(). This figures out and calls the access
> callback for the particular menu item. For the most general case of a menu
> item with a custom access callback, it would probably not be possible to
> modify the function to check a specific $account instead of the current
> global $user, without some sort of hack.
>   --Jennifer
> --
> Jennifer Hodgdon * Poplar ProductivityWare
> www.poplarware.com
> Drupal, WordPress, and custom Web programming

More information about the development mailing list