Commit 13b3e276 authored by webchick's avatar webchick

Issue #1848210 by dysrama, David_Rothstein, kid_icarus, YesCT, Gábor Hojtsy:...

Issue #1848210 by dysrama, David_Rothstein, kid_icarus, YesCT, Gábor Hojtsy: Fixed [Regression] Submitting a form in Overlay shows content + dsm() for a split second before redirecting to front-end theme.
parent dd85e54a
<?php
/**
* @file
* Contains \Drupal\overlay\Tests\OverlayCloseTest.
*/
namespace Drupal\overlay\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests that the overlay can be properly closed.
*/
class OverlayCloseTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('node', 'overlay');
public static function getInfo() {
return array(
'name' => 'Overlay closing functionality',
'description' => 'Test that the overlay can be correctly closed.',
'group' => 'Overlay',
);
}
/**
* Tests that the overlay is correctly closed after creating a node.
*/
function testNodeCreation() {
// Make sure the node creation page is considered an administrative path
// (which will appear in the overlay).
variable_set('node_admin_theme', TRUE);
// Create a content type and a user who has permission to create it inside
// the overlay.
$this->drupalCreateContentType(array('type' => 'test', 'name' => 'Test content type'));
$admin_user = $this->drupalCreateUser(array('access content', 'access overlay', 'create test content'));
$this->drupalLogin($admin_user);
// Create a new node, with ?render=overlay in the query parameter to
// simulate creating it inside the overlay.
$this->drupalPost('node/add/test', array('title' => 'Test node title'), t('Save'), array('query' => array('render' => 'overlay')));
// Make sure a bare minimum HTML page is displayed that contains the
// JavaScript necessary to close the overlay.
$this->assertRaw('<body class="overlay"></body>', 'An empty body tag is present on the page request after a node is created inside the overlay.');
$this->assertRaw('"closeOverlay":true', 'The JavaScript setting for closing the overlay is present on the page request after a node is created inside the overlay.');
// Visit another page and make sure that we now see the message saying the
// node was created (i.e., that it does not appear inside the overlay where
// no one would have time to read it before the overlay closes).
$this->drupalGet('');
$this->assertRaw(t('!post %title has been created.', array('!post' => 'Test content type', '%title' => 'Test node title')), 'Message about the node being created is displayed on the next page request after the overlay is closed.');
}
}
......@@ -571,52 +571,18 @@ function overlay_preprocess_page(&$variables) {
}
}
/**
* Stores and returns whether an empty page override is needed.
*
* This is 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. Instead, we store a variable which will cause the page to be
* rendered by a delivery callback function that does not actually print
* visible HTML (but rather only the bare minimum scripts and styles necessary
* to trigger the overlay to close), 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).
*
* @param $value
* By default, an empty page will not be displayed. Set to TRUE to request
* an empty page display, or FALSE to disable the empty page display (if it
* was previously enabled on this page request).
*
* @return
* TRUE if the current behavior is to display an empty page, or FALSE if not.
*
* @see overlay_page_delivery_callback_alter()
*/
function overlay_display_empty_page($value = NULL) {
$display_empty_page = &drupal_static(__FUNCTION__, FALSE);
if (isset($value)) {
$display_empty_page = $value;
}
return $display_empty_page;
}
/**
* Implements hook_page_delivery_callback_alter().
*/
function overlay_page_delivery_callback_alter(&$callback) {
if (overlay_display_empty_page()) {
$callback = 'overlay_deliver_empty_page';
}
}
/**
* Prints an empty page.
*
* 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.
*
* 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).
*/
function overlay_deliver_empty_page() {
$empty_page = '<html><head><title></title>' . drupal_get_css() . drupal_get_js() . '</head><body class="overlay"></body></html>';
......@@ -749,7 +715,7 @@ function overlay_overlay_child_initialize() {
}
/**
* Requests that the overlay closes when the page is displayed.
* Immediately returns HTML to to the browser and closes the overlay.
*
* @param $redirect
* (optional) The path that should open in the parent window after the
......@@ -759,6 +725,9 @@ function overlay_overlay_child_initialize() {
* @param $redirect_options
* (optional) An associative array of options to use when generating the
* redirect URL.
*
* @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.
*/
function overlay_close_dialog($redirect = NULL, $redirect_options = array()) {
$settings = array(
......@@ -776,7 +745,7 @@ function overlay_close_dialog($redirect = NULL, $redirect_options = array()) {
// 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.
overlay_display_empty_page(TRUE);
overlay_deliver_empty_page();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment