Performs check on the beginning of a request.
Determine whether the current page request is destined to appear in the parent window or in the overlay window, and format the page accordingly.
public function onRequest(GetResponseEvent $event) {
$request = $event
->getRequest();
if ($this->negotiation
->getContentType($request) != 'html') {
// Only act on html pages.
return;
}
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.
$user_data = $this->userData
->get('overlay', $user->uid, 'enabled');
$use_overlay = !isset($user_data) || $user_data;
if (empty($mode) && user_access('access overlay') && $use_overlay) {
$current_path = $request->attributes
->get('system_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']);
$response = new RedirectResponse(url('<front>', array(
'fragment' => 'overlay=' . $current_path,
'absolute' => TRUE,
)));
$event
->setResponse($response);
}
if ($request->query
->get('render') == 'overlay') {
// If a previous page requested that we close the overlay, close it and
// redirect to the final destination.
if (isset($_SESSION['overlay_close_dialog'])) {
$response = call_user_func_array('overlay_close_dialog', $_SESSION['overlay_close_dialog']);
unset($_SESSION['overlay_close_dialog']);
$event
->setResponse($response);
}
elseif (!path_is_admin($current_path)) {
$response = overlay_close_dialog($current_path, array(
'query' => drupal_get_query_parameters(NULL, array(
'render',
)),
));
$event
->setResponse($response);
}
// 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.
$request->query
->remove('render');
}
elseif (!path_is_admin($current_path)) {
// Otherwise add overlay parent code and our behavior.
overlay_set_mode('parent');
}
}
}