From a23bbaa30bb87458521934ffefb3336de85d37ba Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 29 Jul 2009 03:51:16 +0000 Subject: [PATCH] blocks: MDL-19946 More bug fixes. --- blocks/edit_form.php | 12 ++++++++++-- lib/blocklib.php | 11 ++++++++--- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/blocks/edit_form.php b/blocks/edit_form.php index d8c8fcc3f65..b3d6c5faedb 100644 --- a/blocks/edit_form.php +++ b/blocks/edit_form.php @@ -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); diff --git a/lib/blocklib.php b/lib/blocklib.php index 3446c6c8712..df1fb448def 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -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); }