From 658db64435784c0aaf98b42140ebc4957cd3361b Mon Sep 17 00:00:00 2001
From: James Silver <jamsilver@gmail.com>
Date: Thu, 17 Jan 2013 20:05:25 +0000
Subject: [PATCH] Make it work with Omega

---
 blockgroup.module |   24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/blockgroup.module b/blockgroup.module
index 3798da1..27ddb1a 100644
--- a/blockgroup.module
+++ b/blockgroup.module
@@ -88,13 +88,24 @@ function blockgroup_element_info() {
  */
 function blockgroup_pullup($build) {
   // Copy element from base into the build array.
-  if (($key = $build['#key']) && !empty($build['#base'][$key])) {
-    $build[$key] = $build['#base'][$key];
+  if (($key = $build['#key'])) {
+
+    if (!empty($build['#base'][$key])) {
+      $build[$key] = $build['#base'][$key];
+    }
+
+    // It's possible our region was removed from the global $page array by
+    // someone else (e.g. Omega's Alpha module). So we have this backup.
+    elseif (!empty($build['#backup_base'])) {
+      $build[$key] = $build['#backup_base'];
+    }
 
     // Remove pullup parameters from render array.
-    unset($build['#base']);
-    unset($build['#key']);
-    unset($build['#type']);
+    if (isset($build[$key])) {
+      unset($build['#base']);
+      unset($build['#key']);
+      unset($build['#type']);
+    }
 
     return $build;
   }
@@ -307,6 +318,9 @@ function blockgroup_page_alter(&$page) {
       foreach ($blocks as $key => &$build) {
         if (isset($build['#type']) && $build['#type'] == 'blockgroup_pullup') {
           $build['#base'] = &$page;
+          // Also keep a non-reference copy in case anyone removes us.
+          // For example: Alpha's hook_page_alter().
+          $build['#backup_base'] = $page[$build['#key']];
         }
       }
     }
-- 
1.7.10.4

