My employer doesn't like the Drupal navigation block, so we're only using it on the administrative side. Obviously, if we impersonate a non-admin, that leaves us without a way to switch back. I found the url of switch back, but how can I set up the link on the pages so that it only appears if you're masqueraded?

Also, when I masquerade as another admin, the navigation block doesn't appear, even if the other admin can normally see it.

Comments

deviantintegral’s picture

Category: feature » support

Have you tried adding masquerade/unswitch as a custom menu item? The access callback should take care of hiding it if you're not masquerading.

a.bond’s picture

Unfortunately, what my employer wanted for the menu was something completely different than the Drupal menu system, so using the Drupal menus is pretty much out. Is there some kind of block level PHP visibility code that I could set up to handle hiding it?

deviantintegral’s picture

<?php
if (module_exists('masquerade') && $_SESSION['masquerading']) {
  // Do stuff there.
}

That should get you started. It probably belongs in one of your preprocess functions in your theme. What I've done in similar cases is using a combination of preprocess functions and template files to allow the use of the Menu system backend while completely changing the front-end presentation.

a.bond’s picture

Status: Active » Fixed

Thanks, that did the trick! What I did is use that code for a block visibility, and put a link to masquerade/unswitch in the block content. Simple, easy, effective.

Status: Fixed » Closed (fixed)

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

KoCo’s picture

Version: 6.x-1.3 » 7.x-1.x-dev
Priority: Normal » Minor
Status: Closed (fixed) » Active

I thought this would be a good place to ask this little error, when used the code to show a block I get:

Notice: Undefined index: masquerading in eval() (rule 2 van .../modules/php/php.module(74) : eval()'d code).

Pretty sure it has something to do with $_SESSION['masquerading'], but not so sure why.

Is there an easy way to check wether or not you're currently masqeurading?
I went through the code and issues, but neither isset($_SESSION['masquerading'] or return $_SESSION['masquerading'] works.

If someone has a quick answer?

thx
K

KoCo’s picture

Status: Active » Closed (fixed)

Stupid me ;-)

return session_is_registered('masquerading')