From f97946876dba52fcbc0229b8e785cc3d211130f2 Mon Sep 17 00:00:00 2001
From: Jorrit Schippers <jorrit@161217.no-reply.drupal.org>
Date: Fri, 28 Jun 2013 22:11:36 +0200
Subject: [PATCH] Issue #1814516 by Jorrit: Fixed admin pages appearing in
 default theme when the menu needs rebuilding

---
 subpathauto.module |   13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/subpathauto.module b/subpathauto.module
index 4fd2eda..40a5596 100644
--- a/subpathauto.module
+++ b/subpathauto.module
@@ -22,7 +22,20 @@ function subpathauto_menu() {
 function subpathauto_url_inbound_alter(&$path, $original_path, $language) {
   // If the current menu item exists at this path, then we should not continue
   // processing.
+  // menu_get_item() may initialize the theme system when a rebuild is needed.
+  // Ignore this rebuild because it initializes the theme too early, causing
+  // admin paths to be displayed in the front theme.
+  if ($menurebuild = variable_get('menu_rebuild_needed', FALSE)) {
+    global $conf;
+    $conf['menu_rebuild_needed'] = FALSE;
+  }
   $item = menu_get_item($path);
+
+  // Restore the menu_rebuild_needed variable.
+  if ($menurebuild) {
+    $conf['menu_rebuild_needed'] = TRUE;
+  }
+
   if (!empty($item) && $item['href'] == $path) {
     return FALSE;
   }
-- 
1.7.10.4

