function overlay_paths_init in Overlay Paths 7
Implements hook_init().
Determine whether the current page request is destined to appear in the parent window or in the overlay window, and format the page accordingly.
See also
File
- ./
overlay_paths.module, line 64 - The overlay paths module.
Code
function overlay_paths_init() {
global $user;
$mode = overlay_get_mode();
// Only act if the user has access to the overlay and a mode was not already
// set. Other modules can also enable the overlay directly for other uses.
$use_overlay = !isset($user->data['overlay']) || $user->data['overlay'];
if (empty($mode) && user_access('access overlay') && $use_overlay) {
$current_path = current_path();
// After overlay is enabled on the modules page, redirect to
// <front>#overlay=admin/modules to actually enable the overlay.
if (isset($_SESSION['overlay_enable_redirect']) && $_SESSION['overlay_enable_redirect']) {
unset($_SESSION['overlay_enable_redirect']);
drupal_goto('<front>', array(
'fragment' => 'overlay=' . $current_path,
));
}
if (isset($_GET['render']) && $_GET['render'] == 'overlay') {
// redirect to the final destination.
if (isset($_SESSION['overlay_close_dialog'])) {
call_user_func_array('overlay_close_dialog', $_SESSION['overlay_close_dialog']);
unset($_SESSION['overlay_close_dialog']);
}
// If this page shouldn't be rendered here, redirect to the parent.
if (!overlay_paths_is_overlay($current_path)) {
overlay_close_dialog($current_path, array(
'query' => drupal_get_query_parameters(NULL, array(
'q',
'render',
)),
));
}
// Indicate that we are viewing an overlay child page.
overlay_set_mode('child');
// Unset the render parameter to avoid it being included in URLs on the page.
unset($_GET['render']);
}
elseif (!overlay_paths_is_overlay($current_path)) {
// Otherwise add overlay parent code and our behavior.
overlay_set_mode('parent');
}
}
}