]> git.mjollnir.org Git - moodle.git/commitdiff
blocks: MDL-19946 More bug fixes.
authortjhunt <tjhunt>
Wed, 29 Jul 2009 03:51:16 +0000 (03:51 +0000)
committertjhunt <tjhunt>
Wed, 29 Jul 2009 03:51:16 +0000 (03:51 +0000)
blocks/edit_form.php
lib/blocklib.php

index d8c8fcc3f65c1802c2fd2b5ea7f12586cf25c8f0..b3d6c5faedbf5361db13c45c7448bcd87df9153d 100644 (file)
@@ -125,6 +125,14 @@ class block_edit_form extends moodleform {
     }
 
     function set_data($defaults) {
+        // Prefix bui_ on all the core field names.
+        $blockfields = array('showinsubcontexts', 'pagetypepattern', 'subpagepattern',
+                'defaultregion', 'defaultweight', 'visible', 'region', 'weight');
+        foreach ($blockfields as $field) {
+            $newname = 'bui_' . $field;
+            $defaults->$newname = $defaults->$field;
+        }
+
         // Copy block config into config_ fields.
         if (!empty($this->block->config)) {
             foreach ($this->block->config as $field => $value) {
@@ -134,8 +142,8 @@ class block_edit_form extends moodleform {
         }
 
         // Munge ->subpagepattern becuase HTML selects don't play nicely with NULLs.
-        if (empty($defaults->subpagepattern)) {
-            $defaults->subpagepattern = '%@NULL@%';
+        if (empty($defaults->bui_subpagepattern)) {
+            $defaults->bui_subpagepattern = '%@NULL@%';
         }
 
         parent::set_data($defaults);
index 3446c6c8712494d54c778f628b1de011ed1d8f4a..df1fb448def4943e8290af443e40413274b8d127 100644 (file)
@@ -878,6 +878,7 @@ class block_manager {
         }
 
         $mform = new $classname($editpage->url, $block, $this->page);
+        print_object($block); // DONOTCOMMIT
         $mform->set_data($block->instance);
 
         if ($mform->is_cancelled()) {
@@ -897,7 +898,11 @@ class block_manager {
             $bi->defaultweight = $data->bui_defaultweight;
             $DB->update_record('block_instances', $bi);
 
-            $config = clone($block->config);
+            if (!empty($block->config)) {
+                $config = clone($block->config);
+            } else {
+                $config = new stdClass;
+            }
             foreach ($data as $configfield => $value) {
                 if (strpos($configfield, 'config_') !== 0) {
                     continue;
@@ -923,12 +928,12 @@ class block_manager {
 
             } else if ($needbprecord) {
                 $bp->blockinstanceid = $block->instance->id;
-                $bp->contextid = $this->page->contextid;
+                $bp->contextid = $this->page->context->id;
                 $bp->pagetype = $this->page->pagetype;
                 if ($this->page->subpage) {
                     $bp->subpage = $this->page->subpage;
                 } else {
-                    $bp->subpage = null;
+                    $bp->subpage = '';
                 }
                 $DB->insert_record('block_positions', $bp);
             }