#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
<?php
/**
* @file
* Displays the Drupal administration interface in an overlay.
*/
2012-03-27 02:59:03 +00:00
use Symfony\Component\HttpFoundation\Response;
2012-06-04 12:06:09 +00:00
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
2013-05-11 10:01:25 +00:00
use Drupal\block\Plugin\Core\Entity\Block;
2013-06-06 10:20:38 +00:00
use Drupal\user\UserInterface;
2012-03-27 02:59:03 +00:00
2009-12-11 17:08:27 +00:00
/**
* Implements hook_help().
*/
function overlay_help($path, $arg) {
switch ($path) {
case 'admin/help#overlay':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
2012-03-21 05:51:30 +00:00
$output .= '<p>' . t('The Overlay module makes the administration pages on your site display in a JavaScript overlay of the page you were viewing when you clicked the administrative link, instead of replacing the page in your browser window. Use the close link on the overlay to return to the page you were viewing when you clicked the link. For more information, see the online handbook entry for <a href="@overlay">Overlay module</a>.', array('@overlay' => 'http://drupal.org/documentation/modules/overlay')) . '</p>';
2009-12-11 17:08:27 +00:00
return $output;
}
}
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
/**
2012-03-27 02:59:03 +00:00
* Implements hook_menu()
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*/
function overlay_menu() {
$items['overlay-ajax/%'] = array(
'title' => '',
'page callback' => 'overlay_ajax_render_region',
'page arguments' => array(1),
'access arguments' => array('access overlay'),
'type' => MENU_CALLBACK,
);
2010-11-06 00:18:24 +00:00
$items['overlay/dismiss-message'] = array(
'title' => '',
'page callback' => 'overlay_user_dismiss_message',
2012-04-16 19:19:52 +00:00
'access callback' => 'overlay_user_dismiss_message_access',
2010-11-06 00:18:24 +00:00
'type' => MENU_CALLBACK,
);
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
return $items;
}
2010-11-06 00:18:24 +00:00
/**
* Implements hook_admin_paths().
*/
function overlay_admin_paths() {
$paths = array(
// This is marked as an administrative path so that if it is visited from
// within the overlay, the user will stay within the overlay while the
// callback is being processed.
'overlay/dismiss-message' => TRUE,
);
return $paths;
}
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
/**
* Implements hook_permission().
*/
function overlay_permission() {
return array(
'access overlay' => array(
'title' => t('Access the administrative overlay'),
'description' => t('View administrative pages in the overlay.'),
),
);
}
2010-06-08 05:16:29 +00:00
/**
* Implements hook_theme().
*/
function overlay_theme() {
return array(
'overlay' => array(
'render element' => 'page',
'template' => 'overlay',
),
2010-11-06 00:18:24 +00:00
'overlay_disable_message' => array(
'render element' => 'element',
),
2010-06-08 05:16:29 +00:00
);
}
Issue #967566 by Letharion, mariusz.slonina, indytechcook, adnasa, joestewart, oriol_e9g, Fabianx, tim.plunkett, valthebald, tsvenson, rbayliss, sun, xjm | DocuAnt: Several important Core User settings need to implement hook_field_extra_fields().
2013-02-18 21:21:42 +00:00
/**
* Implements hook_field_extra_fields().
*/
function overlay_field_extra_fields() {
$fields['user']['user']['form']['overlay_control'] = array(
'label' => t('Administrative overlay'),
'description' => t('Overlay module form element.'),
'weight' => 4,
);
return $fields;
}
2010-07-28 02:50:00 +00:00
/**
* Implements hook_form_FORM_ID_alter().
*/
function overlay_form_user_profile_form_alter(&$form, &$form_state) {
2013-04-29 23:46:14 +00:00
$account = $form_state['controller']->getEntity();
2011-11-03 07:34:18 +00:00
if (user_access('access overlay', $account)) {
2012-11-27 22:26:22 +00:00
$account_data = drupal_container()->get('user.data')->get('overlay', $account->id(), 'enabled');
2011-11-03 07:34:18 +00:00
$form['overlay_control'] = array(
2012-11-27 07:06:47 +00:00
'#type' => 'details',
2011-11-03 07:34:18 +00:00
'#title' => t('Administrative overlay'),
'#weight' => 4,
);
$form['overlay_control']['overlay'] = array(
'#type' => 'checkbox',
'#title' => t('Use the overlay for administrative pages.'),
'#description' => t('Show administrative pages on top of the page you started from.'),
2012-11-27 22:26:22 +00:00
'#default_value' => isset($account_data) ? $account_data : 1,
2011-11-03 07:34:18 +00:00
);
2010-07-28 02:50:00 +00:00
}
}
/**
2012-11-27 22:26:22 +00:00
* Implements hook_user_update().
2010-07-28 02:50:00 +00:00
*/
2012-11-27 22:26:22 +00:00
function overlay_user_update($account) {
2012-04-26 03:51:09 +00:00
if (isset($account->overlay)) {
2012-11-27 22:26:22 +00:00
drupal_container()->get('user.data')->set('overlay', $account->id(), 'enabled', (int) $account->overlay);
2010-07-28 02:50:00 +00:00
}
}
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
/**
2011-09-24 19:50:19 +00:00
* Implements hook_library_info().
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*/
2011-09-24 19:50:19 +00:00
function overlay_library_info() {
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
$module_path = drupal_get_path('module', 'overlay');
// Overlay parent.
2012-08-30 19:24:38 +00:00
$libraries['drupal.overlay.parent'] = array(
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
'title' => 'Overlay: Parent',
2012-03-21 05:51:30 +00:00
'website' => 'http://drupal.org/documentation/modules/overlay',
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
'version' => '1.0',
'js' => array(
$module_path . '/overlay-parent.js' => array(),
),
'css' => array(
2013-06-07 10:48:55 +00:00
$module_path . '/css/overlay-parent.css' => array(),
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
),
'dependencies' => array(
2012-08-30 19:24:38 +00:00
array('system', 'jquery'),
array('system', 'drupal'),
2012-09-24 13:12:09 +00:00
array('system', 'drupalSettings'),
2013-03-29 15:23:50 +00:00
array('system', 'drupal.displace'),
2013-04-19 17:20:06 +00:00
array('system', 'drupal.tabbingmanager'),
2013-04-20 03:43:48 +00:00
array('system', 'drupal.announce'),
2012-06-24 17:30:34 +00:00
array('system', 'jquery.ui.core'),
2010-11-30 17:16:37 +00:00
array('system', 'jquery.bbq'),
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
),
);
// Overlay child.
2012-08-30 19:24:38 +00:00
$libraries['drupal.overlay.child'] = array(
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
'title' => 'Overlay: Child',
2012-03-21 05:51:30 +00:00
'website' => 'http://drupal.org/documentation/modules/overlay',
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
'version' => '1.0',
'js' => array(
$module_path . '/overlay-child.js' => array(),
),
2010-06-08 05:16:29 +00:00
'css' => array(
2013-06-07 10:48:55 +00:00
$module_path . '/css/overlay-child.css' => array(),
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
),
2012-08-30 19:24:38 +00:00
'dependencies' => array(
array('system', 'jquery'),
array('system', 'drupal'),
2012-09-24 13:12:09 +00:00
array('system', 'drupalSettings'),
2012-08-30 19:24:38 +00:00
array('system', 'jquery.once'),
),
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
);
return $libraries;
}
/**
* Implements hook_drupal_goto_alter().
*/
function overlay_drupal_goto_alter(&$path, &$options, &$http_response_code) {
if (overlay_get_mode() == 'child') {
2011-07-28 19:06:04 +00:00
// The authorize.php script bootstraps Drupal to a very low level, where
// the PHP code that is necessary to close the overlay properly will not be
// loaded. Therefore, if we are redirecting to authorize.php inside the
// overlay, instead redirect back to the current page with instructions to
// close the overlay there before redirecting to the final destination; see
// overlay_init().
if ($path == system_authorized_get_url() || $path == system_authorized_batch_processing_url()) {
$_SESSION['overlay_close_dialog'] = array($path, $options);
$path = current_path();
$options = drupal_get_query_parameters();
}
// If the current page request is inside the overlay, add ?render=overlay
// to the new path, so that it appears correctly inside the overlay.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
if (isset($options['query'])) {
$options['query'] += array('render' => 'overlay');
}
else {
$options['query'] = array('render' => 'overlay');
}
}
}
/**
* Implements hook_batch_alter().
*
* If the current page request is inside the overlay, add ?render=overlay to
* the success callback URL, so that it appears correctly within the overlay.
*
* @see overlay_get_mode()
*/
function overlay_batch_alter(&$batch) {
if (overlay_get_mode() == 'child') {
if (isset($batch['url_options']['query'])) {
$batch['url_options']['query']['render'] = 'overlay';
}
else {
$batch['url_options']['query'] = array('render' => 'overlay');
}
}
}
/**
* Implements hook_page_alter().
*/
function overlay_page_alter(&$page) {
// If we are limiting rendering to a subset of page regions, deny access to
// all other regions so that they will not be processed.
if ($regions_to_render = overlay_get_regions_to_render()) {
$skipped_regions = array_diff(element_children($page), $regions_to_render);
foreach ($skipped_regions as $skipped_region) {
$page[$skipped_region]['#access'] = FALSE;
}
}
2010-06-08 05:16:29 +00:00
2010-11-06 00:18:24 +00:00
$mode = overlay_get_mode();
if ($mode == 'child') {
2010-06-08 05:16:29 +00:00
// Add the overlay wrapper before the html wrapper.
array_unshift($page['#theme_wrappers'], 'overlay');
}
2010-11-06 00:18:24 +00:00
elseif ($mode == 'parent' && ($message = overlay_disable_message())) {
$page['page_top']['disable_overlay'] = $message;
}
}
2012-04-16 19:19:52 +00:00
/**
2012-10-04 16:30:03 +00:00
* Access callback: Determines access to dismiss the accessibility message.
*
* @return
* TRUE if the user has permission to dismiss the accessibility message or if
* the user is anonymous. FALSE if otherwise.
2012-04-16 19:19:52 +00:00
*
* @see overlay_user_dismiss_message()
* @see overlay_menu()
*/
function overlay_user_dismiss_message_access() {
global $user;
if (!user_access('access overlay')) {
return FALSE;
}
2010-11-06 00:18:24 +00:00
// It's unlikely, but possible that "access overlay" permission is granted to
// the anonymous role. In this case, we do not display the message to disable
2012-04-16 19:19:52 +00:00
// the overlay, so there is nothing to dismiss.
if (empty($user->uid)) {
return FALSE;
2010-11-06 00:18:24 +00:00
}
2012-04-16 19:19:52 +00:00
return TRUE;
2010-11-06 00:18:24 +00:00
}
2012-04-28 02:59:33 +00:00
/**
2012-10-04 16:30:03 +00:00
* Page callback: Dismisses the overlay accessibility message for this user.
*
* @return
* A render array for a page containing a list of content.
2012-04-28 02:59:33 +00:00
*
* @see overlay_user_dismiss_message_access()
* @see overlay_menu()
*/
function overlay_user_dismiss_message() {
global $user;
2012-05-24 04:28:17 +00:00
// @todo CSRF tokens are validated in page callbacks rather than access
// callbacks, because access callbacks are also invoked during menu link
// generation. Add token support to routing: http://drupal.org/node/755584.
2012-07-25 05:41:27 +00:00
$token = drupal_container()->get('request')->query->get('token');
2012-05-24 04:28:17 +00:00
if (!isset($token) || !drupal_valid_token($token, 'overlay')) {
2012-06-04 12:06:09 +00:00
throw new AccessDeniedHttpException();
2012-05-24 04:28:17 +00:00
}
2012-11-27 22:26:22 +00:00
drupal_container()->get('user.data')->set('overlay', $user->uid, 'message_dismissed', 1);
2012-04-28 02:59:33 +00:00
drupal_set_message(t('The message has been dismissed. You can change your overlay settings at any time by visiting your profile page.'));
// Destination is normally given. Go to the user profile as a fallback.
drupal_goto('user/' . $user->uid . '/edit');
2010-11-06 00:18:24 +00:00
}
/**
* Returns a renderable array representing a message for disabling the overlay.
*
* If the current user can access the overlay and has not previously indicated
* that this message should be dismissed, this function returns a message
* containing a link to disable the overlay. Nothing is returned for anonymous
2012-10-02 16:29:50 +00:00
* users, because the links control per-user settings. Because some screen
* readers are unable to properly read overlay contents, site builders are
* discouraged from granting the "access overlay" permission to the anonymous
* role.
*
* @see http://drupal.org/node/890284
2010-11-06 00:18:24 +00:00
*/
function overlay_disable_message() {
global $user;
2012-11-27 22:26:22 +00:00
$build = array();
if (empty($user->uid) || !user_access('access overlay')) {
return $build;
}
$user_data = drupal_container()->get('user.data')->get('overlay', $user->uid);
if (empty($user_data['message_dismissed']) && (!isset($user_data['enabled']) || $user_data['enabled'])) {
2010-11-06 00:18:24 +00:00
$build = array(
'#theme' => 'overlay_disable_message',
'#weight' => -99,
// Link to the user's profile page, where the overlay can be disabled.
'profile_link' => array(
'#type' => 'link',
'#title' => t('If you have problems accessing administrative pages on this site, disable the overlay on your profile page.'),
'#href' => 'user/' . $user->uid . '/edit',
'#options' => array(
'query' => drupal_get_destination(),
'fragment' => 'edit-overlay-control',
'attributes' => array(
'id' => 'overlay-profile-link',
// Prevent the target page from being opened in the overlay.
'class' => array('overlay-exclude'),
),
),
),
// Link to a menu callback that allows this message to be permanently
// dismissed for the current user.
'dismiss_message_link' => array(
'#type' => 'link',
'#title' => t('Dismiss this message.'),
'#href' => 'overlay/dismiss-message',
'#options' => array(
'query' => drupal_get_destination() + array(
// Add a token to protect against cross-site request forgeries.
'token' => drupal_get_token('overlay'),
),
'attributes' => array(
'id' => 'overlay-dismiss-message',
// If this message is being displayed outside the overlay, prevent
// this link from opening the overlay.
'class' => (overlay_get_mode() == 'parent') ? array('overlay-exclude') : array(),
),
),
)
);
}
return $build;
}
/**
* Returns the HTML for the message about how to disable the overlay.
*
2012-10-02 16:29:50 +00:00
* @param $variables
* An associative array with an 'element' element, which itself is an
* associative array containing:
* - profile_link: The link to this user's account.
* - dismiss_message_link: The link to dismiss the overlay.
*
* @ingroup themeable
2010-11-06 00:18:24 +00:00
*/
function theme_overlay_disable_message($variables) {
$element = $variables['element'];
// Add CSS classes to hide the links from most sighted users, while keeping
// them accessible to screen-reader users and keyboard-only users. To assist
// screen-reader users, this message appears in both the parent and child
// documents, but only the one in the child document is part of the tab order.
foreach (array('profile_link', 'dismiss_message_link') as $key) {
$element[$key]['#options']['attributes']['class'][] = 'element-invisible';
if (overlay_get_mode() == 'child') {
$element[$key]['#options']['attributes']['class'][] = 'element-focusable';
}
}
// Render the links.
$output = drupal_render($element['profile_link']) . ' ' . drupal_render($element['dismiss_message_link']);
// Add a heading for screen-reader users. The heading doesn't need to be seen
// by sighted users.
$output = '<h3 class="element-invisible">' . t('Options for the administrative overlay') . '</h3>' . $output;
// Wrap in a container for styling.
$output = '<div id="overlay-disable-message" class="clearfix">' . $output . '</div>';
return $output;
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
}
/**
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
* Implements hook_block_access().
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*/
2013-06-06 10:20:38 +00:00
function overlay_block_access(Block $block, $operation, UserInterface $account, $langcode) {
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
// If we are limiting rendering to a subset of page regions, hide all blocks
// which appear in regions not on that list. Note that overlay_page_alter()
// does a more comprehensive job of preventing unwanted regions from being
// displayed (regardless of whether they contain blocks or not), but the
// reason for duplicating effort here is performance; we do not even want
// these blocks to be built if they are not going to be displayed.
if ($regions_to_render = overlay_get_regions_to_render()) {
2013-01-17 04:03:30 +00:00
if (!in_array($block->get('region'), $regions_to_render)) {
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
return FALSE;
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
}
}
}
/**
* Implements hook_system_info_alter().
*
* Add default regions for the overlay.
*/
function overlay_system_info_alter(&$info, $file, $type) {
if ($type == 'theme') {
$info['overlay_regions'][] = 'content';
$info['overlay_regions'][] = 'help';
}
}
/**
2012-05-04 19:53:43 +00:00
* Implements hook_preprocess_HOOK() for html.tpl.php.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
* If the current page request is inside the overlay, add appropriate classes
* to the <body> element, and simplify the page title.
*
* @see overlay_get_mode()
*/
function overlay_preprocess_html(&$variables) {
if (overlay_get_mode() == 'child') {
// Add overlay class, so themes can react to being displayed in the overlay.
2012-08-03 15:31:18 +00:00
$variables['attributes']['class'][] = 'overlay';
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
}
}
2010-01-14 03:25:43 +00:00
/**
2013-05-24 16:48:56 +00:00
* Implements hook_preprocess_HOOK() for maintenance-page.html.twig.
2010-01-14 03:25:43 +00:00
*
* If the current page request is inside the overlay, add appropriate classes
* to the <body> element, and simplify the page title.
*/
function overlay_preprocess_maintenance_page(&$variables) {
overlay_preprocess_html($variables);
}
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
/**
2012-10-02 16:29:50 +00:00
* Implements template_preprocess_HOOK() for overlay.tpl.php
*
* If the current page request is inside the overlay, add appropriate classes
* to the <body> element, and simplify the page title.
2010-06-08 05:16:29 +00:00
*
2012-10-02 16:29:50 +00:00
* @see template_process_overlay()
2010-06-08 05:16:29 +00:00
* @see overlay.tpl.php
*/
function template_preprocess_overlay(&$variables) {
2010-11-06 00:18:24 +00:00
$variables['tabs'] = menu_primary_local_tasks();
$variables['title'] = drupal_get_title();
$variables['disable_overlay'] = overlay_disable_message();
2013-05-15 18:59:43 +00:00
2013-05-24 16:50:34 +00:00
// Add attributes for the overlay container.
$variables['attributes']['id'] = 'overlay';
2013-05-15 18:59:43 +00:00
$variables['attributes']['class'][] = 'overlay';
2013-05-24 16:50:34 +00:00
// Add attributes for the overlay title.
$variables['title_attributes']['id'] = 'overlay-title';
2013-05-15 18:59:43 +00:00
// Add attributes for the overlay content.
2013-05-24 16:50:34 +00:00
$variables['content_attributes']['id'] = 'overlay-content';
2012-08-03 15:31:18 +00:00
$variables['content_attributes']['class'][] = 'clearfix';
2010-06-08 05:16:29 +00:00
}
/**
2012-10-02 16:29:50 +00:00
* Implements template_process_HOOK() for overlay.tpl.php
*
* Places the rendered HTML for the page body into a top level variable.
2010-06-08 05:16:29 +00:00
*
* @see template_preprocess_overlay()
* @see overlay.tpl.php
*/
function template_process_overlay(&$variables) {
$variables['page'] = $variables['page']['#children'];
}
/**
2012-05-04 19:53:43 +00:00
* Implements hook_preprocess_HOOK() for page.tpl.php.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
2012-10-02 16:29:50 +00:00
* If the current page request is inside the overlay, hide the tabs.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
* @see overlay_get_mode()
*/
function overlay_preprocess_page(&$variables) {
if (overlay_get_mode() == 'child') {
2010-11-20 04:03:51 +00:00
unset($variables['tabs']['#primary']);
2010-06-08 05:16:29 +00:00
}
2010-05-23 18:23:32 +00:00
}
2010-04-21 07:23:10 +00:00
/**
2012-10-02 16:29:50 +00:00
* Prints an empty page.
2010-04-21 07:23:10 +00:00
*
* This function is used to print out a bare minimum empty page which still has
* the scripts and styles necessary in order to trigger the overlay to close.
2013-04-09 21:07:19 +00:00
*
* It can be used to prevent a page request which closes the overlay (for
* example, a form submission) from being fully re-rendered before the overlay
* is closed, thereby allowing the dialog to be closed faster and with less
* interruption, and also allowing the display of messages to be deferred to
* the parent window (rather than displaying them in the child window, which
* will close before the user has had a chance to read them).
2010-04-21 07:23:10 +00:00
*/
function overlay_deliver_empty_page() {
$empty_page = '<html><head><title></title>' . drupal_get_css() . drupal_get_js() . '</head><body class="overlay"></body></html>';
print $empty_page;
drupal_exit();
}
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
/**
2012-10-02 16:29:50 +00:00
* Gets the current overlay mode.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
* @see overlay_set_mode()
*/
function overlay_get_mode() {
return overlay_set_mode(NULL);
}
/**
2010-06-11 12:30:30 +00:00
* Sets the overlay mode and adds proper JavaScript and styles to the page.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
2010-06-11 12:30:30 +00:00
* Note that since setting the overlay mode triggers a variety of behaviors
* (including hooks being invoked), it can only be done once per page request.
* Therefore, the first call to this function which passes along a value of the
* $mode parameter controls the overlay mode that will be used.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
2010-06-11 12:30:30 +00:00
* @param $mode
* To set the mode, pass in one of the following values:
* - 'parent': This is used in the context of a parent window (a regular
* browser window). If set, JavaScript is added so that administrative
* links in the parent window will open in an overlay.
* - 'child': This is used in the context of the child overlay window (the
* page actually appearing within the overlay iframe). If set, JavaScript
* and CSS are added so that Drupal behaves nicely from within the overlay.
* - 'none': This is used to avoid adding any overlay-related code to the
* page at all. Modules can set this to explicitly prevent the overlay from
* being used. For example, since the overlay module itself sets the mode
2013-06-05 07:47:39 +00:00
* to 'parent' or 'child' in the overlay event subscriber when certain
* conditions are met, other modules which want to override that behavior
* can do so by setting the mode to 'none' earlier in the page request -
* e.g., in their own event subscribers, if they have a higher priority.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
* This parameter is optional, and if omitted, the current mode will be
* returned with no action taken.
*
* @return
* The current mode, if any has been set, or NULL if no mode has been set.
*
* @ingroup overlay_api
2013-06-05 07:47:39 +00:00
* @see \Drupal\overlay\EventSubscriber\OverlaySubscriber::onRequest()
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*/
function overlay_set_mode($mode = NULL) {
global $base_path;
$overlay_mode = &drupal_static(__FUNCTION__);
// Make sure external resources are not included more than once. Also return
// the current mode, if no mode was specified.
if (isset($overlay_mode) || !isset($mode)) {
return $overlay_mode;
}
$overlay_mode = $mode;
switch ($overlay_mode) {
case 'parent':
2012-09-04 04:21:47 +00:00
drupal_add_library('overlay', 'drupal.overlay.parent');
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
// Allow modules to act upon overlay events.
module_invoke_all('overlay_parent_initialize');
break;
case 'child':
2012-09-04 04:21:47 +00:00
drupal_add_library('overlay', 'drupal.overlay.child');
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
// Allow modules to act upon overlay events.
module_invoke_all('overlay_child_initialize');
break;
}
return $overlay_mode;
}
/**
* Implements hook_overlay_parent_initialize().
*/
function overlay_overlay_parent_initialize() {
// Let the client side know which paths are administrative.
$paths = path_get_admin_paths();
foreach ($paths as &$type) {
2012-07-02 17:20:33 +00:00
$type = str_replace('<front>', config('system.site')->get('page.front'), $type);
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
}
drupal_add_js(array('overlay' => array('paths' => $paths)), 'setting');
2012-03-07 18:40:48 +00:00
$path_prefixes = array();
2012-04-11 14:47:06 +00:00
if (module_exists('language')) {
language_negotiation_include();
2012-10-27 22:27:04 +00:00
if (config('language.negotiation')->get('url.source') == LANGUAGE_NEGOTIATION_URL_PREFIX) {
2012-04-11 14:47:06 +00:00
// Skip the empty string indicating the default language. We always accept
// paths without a prefix.
$path_prefixes = language_negotiation_url_prefixes();
$path_prefixes = array_values(array_filter($path_prefixes));
}
2012-03-07 18:40:48 +00:00
}
drupal_add_js(array('overlay' => array('pathPrefixes' => $path_prefixes)), 'setting');
2011-02-19 00:09:11 +00:00
// Pass along the Ajax callback for rerendering sections of the parent window.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
drupal_add_js(array('overlay' => array('ajaxCallback' => 'overlay-ajax')), 'setting');
}
/**
* Implements hook_overlay_child_initialize().
*/
function overlay_overlay_child_initialize() {
// Check if the parent window needs to refresh any page regions on this page
// request.
2010-07-08 12:20:23 +00:00
overlay_trigger_refresh();
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
// If this is a POST request, or a GET request with a token parameter, we
// have an indication that something in the supplemental regions of the
// overlay might change during the current page request. We therefore store
// the initial rendered content of those regions here, so that we can compare
2013-05-05 21:09:00 +00:00
// it to the same content rendered in OverlaySubscriber::onResponse(),
// at the end of the page request. This allows us to check if anything
// actually did change, and, if so, trigger an immediate Ajax refresh
// of the parent window.
2012-07-25 05:41:27 +00:00
$token = drupal_container()->get('request')->query->get('token');
2012-04-16 19:42:18 +00:00
if (!empty($_POST) || isset($token)) {
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
foreach (overlay_supplemental_regions() as $region) {
overlay_store_rendered_content($region, overlay_render_region($region));
}
2010-07-08 12:20:23 +00:00
// In addition, notify the parent window that when the overlay closes,
// the entire parent window should be refreshed.
overlay_request_page_refresh();
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
}
// Indicate that when the main page rendering occurs later in the page
// request, only the regions that appear within the overlay should be
// rendered.
overlay_set_regions_to_render(overlay_regions());
}
/**
2013-04-09 21:07:19 +00:00
* Immediately returns HTML to to the browser and closes the overlay.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
* @param $redirect
2010-04-24 07:14:29 +00:00
* (optional) The path that should open in the parent window after the
* overlay closes. If not set, no redirect will be performed on the parent
* window.
2012-10-04 16:30:03 +00:00
*
2010-04-24 07:14:29 +00:00
* @param $redirect_options
* (optional) An associative array of options to use when generating the
* redirect URL.
2013-04-09 21:07:19 +00:00
*
* @todo This function should only request that the overlay close when the page
* is displayed (as it did in Drupal 7), not immediately end the request.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*/
2010-04-24 07:14:29 +00:00
function overlay_close_dialog($redirect = NULL, $redirect_options = array()) {
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
$settings = array(
'overlayChild' => array(
'closeOverlay' => TRUE,
),
);
2010-04-24 07:14:29 +00:00
// Tell the child window to perform the redirection when requested to.
if (isset($redirect)) {
$settings['overlayChild']['redirect'] = url($redirect, $redirect_options);
}
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
drupal_add_js($settings, array('type' => 'setting'));
2010-04-24 07:14:29 +00:00
// Since we are closing the overlay as soon as the page is displayed, we do
// not want to show any of the page's actual content.
2013-04-09 21:07:19 +00:00
overlay_deliver_empty_page();
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
}
/**
* Returns a list of page regions that appear in the overlay.
*
* Overlay regions correspond to the entire contents of the overlay child
* window and are refreshed each time a new page request is made within the
* overlay.
*
* @return
* An array of region names that correspond to those which appear in the
* overlay, within the theme that is being used to display the current page.
*
* @see overlay_supplemental_regions()
*/
function overlay_regions() {
return _overlay_region_list('overlay_regions');
}
/**
* Returns a list of supplemental page regions for the overlay.
*
* Supplemental overlay regions are those which are technically part of the
* parent window, but appear to the user as being related to the overlay
* (usually because they are displayed next to, rather than underneath, the
* main overlay regions) and therefore need to be dynamically refreshed if any
* administrative actions taken within the overlay change their contents.
*
* An example of a typical overlay supplemental region would be the 'page_top'
* region, in the case where a toolbar is being displayed there.
*
* @return
* An array of region names that correspond to supplemental overlay regions,
* within the theme that is being used to display the current page.
*
* @see overlay_regions()
*/
function overlay_supplemental_regions() {
return _overlay_region_list('overlay_supplemental_regions');
}
/**
2012-10-02 16:29:50 +00:00
* Returns a list of page regions related to the overlay.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
* @param $type
* The type of regions to return. This can either be 'overlay_regions' or
* 'overlay_supplemental_regions'.
*
* @return
* An array of region names of the given type, within the theme that is being
* used to display the current page.
*
* @see overlay_regions()
* @see overlay_supplemental_regions()
*/
function _overlay_region_list($type) {
// Obtain the current theme. We need to first make sure the theme system is
// initialized, since this function can be called early in the page request.
drupal_theme_initialize();
$themes = list_themes();
$theme = $themes[$GLOBALS['theme']];
// Return the list of regions stored within the theme's info array, or an
// empty array if no regions of the appropriate type are defined.
return !empty($theme->info[$type]) ? $theme->info[$type] : array();
}
/**
* Returns a list of page regions that rendering should be limited to.
*
* @return
* An array containing the names of the regions that will be rendered when
* drupal_render_page() is called. If empty, then no limits will be imposed,
* and all regions of the page will be rendered.
*
* @see overlay_page_alter()
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
* @see overlay_block_access()
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
* @see overlay_set_regions_to_render()
*/
function overlay_get_regions_to_render() {
return overlay_set_regions_to_render();
}
/**
* Sets the regions of the page that rendering will be limited to.
*
* @param $regions
* (Optional) An array containing the names of the regions that should be
* rendered when drupal_render_page() is called. Pass in an empty array to
* remove all limits and cause drupal_render_page() to render all page
* regions (the default behavior). If this parameter is omitted, no change
* will be made to the current list of regions to render.
*
* @return
* The current list of regions to render, or an empty array if the regions
* are not being limited.
*
* @see overlay_page_alter()
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
* @see overlay_block_access()
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
* @see overlay_get_regions_to_render()
*/
function overlay_set_regions_to_render($regions = NULL) {
$regions_to_render = &drupal_static(__FUNCTION__, array());
if (isset($regions)) {
$regions_to_render = $regions;
}
return $regions_to_render;
}
/**
* Renders an individual page region.
*
* This function is primarily intended to be used for checking the content of
* supplemental overlay regions (e.g., a region containing a toolbar). Passing
* in a region that is intended to display the main page content is not
* supported; the region will be rendered by this function, but the main page
2010-07-28 01:21:58 +00:00
* content will not appear in it. In addition, although this function returns
* the rendered HTML for the provided region, it does not place it on the final
* page, nor add any of its associated JavaScript or CSS to the page.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
* @param $region
* The name of the page region that should be rendered.
*
* @return
* The rendered HTML of the provided region.
*/
function overlay_render_region($region) {
// Indicate the region that we will be rendering, so that other regions will
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
// be hidden by overlay_page_alter() and overlay_block_access().
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
overlay_set_regions_to_render(array($region));
// Do what is necessary to force drupal_render_page() to only display HTML
// from the requested region. Specifically, declare that the main page
// content does not need to automatically be added to the page, and pass in
// a page array that has all theme functions removed (so that overall HTML
// for the page will not be added either).
$system_main_content_added = &drupal_static('system_main_content_added');
$system_main_content_added = TRUE;
$page = array(
'#type' => 'page',
'#theme' => NULL,
'#theme_wrappers' => array(),
);
2010-07-28 01:21:58 +00:00
// Render the region, but do not cache any JavaScript or CSS associated with
// it. This region might not be included the next time drupal_render_page()
// is called, and we do not want its JavaScript or CSS to erroneously appear
// on the final rendered page.
$original_js = drupal_add_js();
$original_css = drupal_add_css();
2011-06-09 03:48:51 +00:00
$original_libraries = drupal_static('drupal_add_library');
2010-07-28 01:21:58 +00:00
$js = &drupal_static('drupal_add_js');
$css = &drupal_static('drupal_add_css');
2011-06-09 03:48:51 +00:00
$libraries = &drupal_static('drupal_add_library');
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
$markup = drupal_render_page($page);
2010-07-28 01:21:58 +00:00
$js = $original_js;
$css = $original_css;
2011-06-09 03:48:51 +00:00
$libraries = $original_libraries;
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
// Indicate that the main page content has not, in fact, been displayed, so
// that future calls to drupal_render_page() will be able to render it
// correctly.
$system_main_content_added = FALSE;
// Restore the original behavior of rendering all regions for the next time
// drupal_render_page() is called.
overlay_set_regions_to_render(array());
return $markup;
}
/**
* Returns any rendered content that was stored earlier in the page request.
*
* @return
* An array of all rendered HTML that was stored earlier in the page request,
* keyed by the identifier with which it was stored. If no content was
* stored, an empty array is returned.
*
* @see overlay_store_rendered_content()
*/
function overlay_get_rendered_content() {
return overlay_store_rendered_content();
}
/**
* Stores strings representing rendered HTML content.
*
* This function is used to keep a static cache of rendered content that can be
* referred to later in the page request.
*
* @param $id
* (Optional) An identifier for the content which is being stored, which will
* be used as an array key in the returned array. If omitted, no change will
* be made to the current stored data.
* @param $content
* (Optional) A string representing the rendered data to store. This only has
* an effect if $id is also provided.
*
* @return
* An array representing all data that is currently being stored, or an empty
* array if there is none.
*
* @see overlay_get_rendered_content()
*/
function overlay_store_rendered_content($id = NULL, $content = NULL) {
$rendered_content = &drupal_static(__FUNCTION__, array());
if (isset($id)) {
$rendered_content[$id] = $content;
}
return $rendered_content;
}
/**
2012-10-04 16:30:03 +00:00
* Requests that the parent window refreshes a particular page region.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
* @param $region
* The name of the page region to refresh. The parent window will trigger a
* refresh of this region on the next page load.
*
2010-07-08 12:20:23 +00:00
* @see overlay_trigger_refresh()
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
* @see Drupal.overlay.refreshRegions()
*/
function overlay_request_refresh($region) {
$class = drupal_region_class($region);
$_SESSION['overlay_regions_to_refresh'][] = array($class => $region);
}
/**
2012-10-04 16:30:03 +00:00
* Requests that the entire parent window is reloaded when the overlay closes.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
2010-07-08 12:20:23 +00:00
* @see overlay_trigger_refresh()
*/
function overlay_request_page_refresh() {
$_SESSION['overlay_refresh_parent'] = TRUE;
}
/**
2012-10-04 16:30:03 +00:00
* Checks if the parent window needs to be refreshed on this page load.
2010-07-08 12:20:23 +00:00
*
* If the previous page load requested that any page regions be refreshed, or
* if it requested that the entire page be refreshed when the overlay closes,
* pass that request via JavaScript to the child window, so it can in turn pass
* the request to the parent window.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
* @see overlay_request_refresh()
2010-07-08 12:20:23 +00:00
* @see overlay_request_page_refresh()
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
* @see Drupal.overlay.refreshRegions()
*/
2010-07-08 12:20:23 +00:00
function overlay_trigger_refresh() {
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
if (!empty($_SESSION['overlay_regions_to_refresh'])) {
$settings = array(
'overlayChild' => array(
'refreshRegions' => $_SESSION['overlay_regions_to_refresh'],
),
);
drupal_add_js($settings, array('type' => 'setting'));
unset($_SESSION['overlay_regions_to_refresh']);
}
2010-07-08 12:20:23 +00:00
if (!empty($_SESSION['overlay_refresh_parent'])) {
drupal_add_js(array('overlayChild' => array('refreshPage' => TRUE)), array('type' => 'setting'));
unset($_SESSION['overlay_refresh_parent']);
}
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
}
/**
* Prints the markup obtained by rendering a single region of the page.
*
2011-02-19 00:09:11 +00:00
* This function is intended to be called via Ajax.
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
*
* @param $region
* The name of the page region to render.
*
* @see Drupal.overlay.refreshRegions()
*/
function overlay_ajax_render_region($region) {
2012-03-27 02:59:03 +00:00
return new Response(overlay_render_region($region));
#610234 by Gábor Hojtsy, ksenzee, cwgordon7, David_Rothstein, seutje, marcvangend, sun, JoshuaRogers, markus_petrux, Bojhan, Rob Loach, Everett Zufelt, drifter, markboulton, leisareichelt, et al: Added Overlay module to core, which shows administrative pages in a JS overlay, retaining context on the front-end site.
2009-12-02 07:28:22 +00:00
}