Just comparing modules, and Masquerade is far preferable to Devel Switch User, since it offers a more intuitive UI for switching back. However, there is one feature that's really convenient in devel in that it provides a path for switching, i.e. /devel/switch/[USERNAME]

Is there a reason why the masquerade function can't be provided as a path?

In my case, I'm trying to create a view field for a view so that I can provide a link such as "Masquerade as user" to go on an admin menu. A masquerade path would make this possible.

Thanks for the great module! I didn't see any place for an easy quick fix in the .module file, but if someone were to point me in the right direction, I might be able to work on it :)

Comments

A path like that is susceptible to cross-site request forgeries. The links need a dynamic token added to them. Short of a patch to this module to add the Views' field (which wouldn't be all that hard -- I should contribute that), there are a couple of ways to pull that off.

One way to do it is to install the Views Custom Field module and add a PHP Code field to your view that contains php like this:

<?php
print l('masquerade','masquerade/switch/' . $data->uid, array('query' => array('token' => drupal_get_token('masquerade/switch/' . $data->uid))));
?>

Or you could use similar code in a preprocessor in a custom module or your theme or in a template override in your theme.

If you install Views Custom Field you really have to trust people who can edit Views.

You really, really shouldn't have Devel enabled on production.

I created a views' field masquerade link for my site. I will post it here once I clean it up. Its very basic, but could be a good starting point.

Status:Active» Closed (won't fix)

Masquerade worked as you describe before masquerade 6.x-1.4, but unfortunately it changed for security.

http://drupal.org/node/835900

oh hey, thanks deekayen :)

@krlucas, I tried your method to achieve this and it seems to generate the token fine, but I can't seem to get it to add the UID properly. Any more thoughts on creating a patch to fix this?

Thanks!

I would also appreciate that.

Thanks
Jaya

Thank you krlucas, your code snippet worked perfectly for me!

Now my custom admin user list view has a nifty masquerade link next to each user! +1 million internet points my friend!