Im developing a module which shows a bar (fixed, top, z-index 99999) with some content. When im in the admin interface with overlay, I want to hide the module, right now the bar is overlapping the overlay.

This code is working well if the overlay is not activated

if (arg(0) == 'admin' || arg(0) == '#overlay=admin') { $output = NULL; }

only the arg(0) == '#overlay=admin' part is not working,

any ideas?

Thanks in advance

  • 1
    The # portion of the URL is a client-side thing, it doesn't get sent to the server so it'll never be available using arg() (or any other PHP method) – Clive Jun 28 '12 at 11:42
  • thanks for answering, I've already tried without the #, but that doesn't work either. – mhmdrupal Jun 28 '12 at 11:44
  • That entire string, #overlay-admin, will never be sent to the server...anything after the # is considered a client-side URL fragment and doesn't get sent to the server when a page is requested – Clive Jun 28 '12 at 11:48
  • hmm.. okay thanks :) got any ideas for a fix? – mhmdrupal Jun 28 '12 at 11:52
  • 1
    Just to understand, where are you using that code? What is the name of the function that includes such code? – kiamlaluno Jun 28 '12 at 13:24

You should use the following code, if you want to avoid outputting something when the overlay is visualized.

if (module_exists('overlay') && path_is_admin($_GET['q'])) {
  // The overlay is visualized.

path_is_admin() is used from overlay_init(), which contains the following code.

  // If this page shouldn't be rendered inside the overlay, redirect to the
  // parent.
  elseif (!path_is_admin($current_path)) {
    overlay_close_dialog($current_path, array('query' => drupal_get_query_parameters(NULL, array('q', 'render'))));
  • can't get this to work either, thanks for pointing the right direction though, I should be able to fix this now. – mhmdrupal Jun 28 '12 at 13:22
  • 1
    That's the function I was looking for :) – Clive Jun 28 '12 at 14:07

Could you not just hide your bar with CSS when the Overlay?

Say for example the parent ID of your bar is #my-admin-bar just write the following in a mymodule.css file:

body.overlay #my-admin-bar {
  display: none;

Then include the mymodule.css file in your module's .info file.

You could also take a look at overlay_get_mode() which checks the current overlay mode (child, parent or none).

This is completely untested, and may not do even nearly what I think it should do but here goes:

//Check if the overlay module is active first otherwise the
// overlay_get_mode() function won't be available and you'll get a WSOD
if (module_exists('overlay')){
  //Get the current path
  $current_path = current_path();
  //Get the overlay mode
  $overlay_mode = overlay_get_mode();
  //This bit should be self-explanatory
  if (path_is_admin($current_path) && $overlay_mode != 'none') {
    //The overlay is active and you are on an admin page!

Function documentation:




overlay_get_mode() (FYI: this is just a wrapper for overlay_set_mode())


I think the easiest way would be to check whether the overlay module is enabled, and just test the URL for the current page request to see if it contains 'admin'. If the overlay is enabled, by default all paths that start with 'admin' will automatically bring up the overlay so this should work (I haven't tested it though):

if (module_exists('overlay') && arg(0) == 'admin') {
  // ...

Note that this won't work for pages that open in the overlay without 'admin' in the path (e.g. node/add). If you want to do the same for those, you'll probably need to invoke hook_admin_paths() to get a list of pages and then test the current URL against those as well.

  • nice approach, thanks for the answer :) however, it didn't work.. ill keep trying with the direction you've provided – mhmdrupal Jun 28 '12 at 12:23

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.