Commit aa14c1cc authored by Arto's avatar Arto

Added a hook_exit() handler to ensure session messages set on form submission...

Added a hook_exit() handler to ensure session messages set on form submission will get shown on the next page despite that page having been cached by Boost.
parent fc1e6cc1
......@@ -43,6 +43,18 @@ function boost_is_cacheable($path) {
return !(BOOST_CACHEABILITY_OPTION xor preg_match($regexp, $alias));
* Determines whether a given Drupal page is currently cached or not.
function boost_is_cached($path) {
$path = (empty($path) ? BOOST_FRONTPAGE : $path);
$alias = drupal_get_path_alias($path);
$path = drupal_get_normal_path($path); // normalize path
// TODO: also determine if alias/symlink exists?
return file_exists(boost_file_path($path));
* Deletes all static files currently in the cache.
......@@ -114,6 +114,47 @@ function boost_init() {
* Implementation of hook_exit(). Performs cleanup tasks.
* For POST requests by anonymous visitors, this adds a dummy query string
* to any URL being redirected to using drupal_goto().
* This is pretty much a hack that assumes a bit too much familiarity with
* what happens under the hood of the Drupal core function drupal_goto().
* It's necessary, though, in order for any session messages set on form
* submission to actually show up on the next page if that page has been
* cached by Boost.
function boost_exit($destination = NULL) {
// Check that hook_exit() was invoked by drupal_goto() for a POST request:
if (!empty($destination) && $_SERVER['REQUEST_METHOD'] == 'POST') {
// Check that we're dealing with an anonymous visitor. and that some
// session messages have actually been set during this page request:
global $user;
if (empty($user->uid) && ($messages = drupal_set_message())) {
// Check that the page we're redirecting to has been cached by Boost
// and really necessitates special handling:
$path = ($path == base_path() ? '' : substr($path, strlen(base_path())));
if (boost_is_cached($path) && empty($query)) {
// FIXME: call any remaining exit hooks since we're about to terminate.
// Add a query string to ensure we don't serve a static copy of
// the page we're redirecting to, which would prevent the session
// messages from showing up:
$destination = url($path, 't=' . time(), $fragment, TRUE);
// Do what drupal_goto() would do if we were to return to it:
exit(header('Location: ' . $destination));
* Implementation of hook_form_alter(). Performs alterations before a form
* is rendered.
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