MDL-43714 blocks: fixed notice when moving to an empty region
authorSam Hemelryk <sam@moodle.com>
Thu, 16 Jan 2014 21:45:23 +0000 (10:45 +1300)
committerSam Hemelryk <sam@moodle.com>
Thu, 16 Jan 2014 21:45:23 +0000 (10:45 +1300)
lib/ajax/blocks.php

index ab24525..e78b756 100644 (file)
@@ -88,9 +88,14 @@ switch ($action) {
 
         $bui_newweight = null;
         if ($bui_beforeid == 0) {
-            // Moving to very bottom
-            $last = end($instances);
-            $bui_newweight = $last->instance->weight + 1;
+            if (count($instances) === 0) {
+                // Moving the block into an empty region. Give it the default weight.
+                $bui_newweight = 0;
+            } else {
+                // Moving to very bottom.
+                $last = end($instances);
+                $bui_newweight = $last->instance->weight + 1;
+            }
         } else {
             // Moving somewhere
             $lastweight = 0;