Commit ad5c3230 authored by Nathan Lewis's avatar Nathan Lewis Committed by Dave Cooper
Browse files

MDL-49306 blocks: Copy instance data when copying block instances

parent d8727a4d
......@@ -501,6 +501,15 @@ class block_base {
return true;
* Copy any block-specific data when copying to a new block instance.
* @param int $fromid the id number of the block instance to copy from
* @return boolean
public function instance_copy($fromid) {
return true;
* Delete everything related to this instance if you have been using persistent storage other than the configdata field.
* @return boolean
......@@ -5,6 +5,8 @@ information provided here is intended especially for developers.
* The obsolete method preferred_width() was removed (it was not doing anything)
* Deprecated block_base::config_save as is not called anywhere and should not be used.
* Added instance_copy() function to the block_base class. This function allows for block
specific data to be copied when a block is copied.
=== 2.8 ===
......@@ -81,11 +81,17 @@ function my_copy_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') {
'pagetypepattern' => $pagetype,
'subpagepattern' => $systempage->id));
foreach ($blockinstances as $instance) {
$originalid = $instance->id;
$instance->parentcontextid = $usercontext->id;
$instance->subpagepattern = $page->id;
$instance->id = $DB->insert_record('block_instances', $instance);
$blockcontext = context_block::instance($instance->id); // Just creates the context record
$block = block_instance($instance->blockname, $instance);
if (!$block->instance_copy($originalid)) {
debugging("Unable to copy block-specific data for original block instance: $originalid
to new block instance: $instance->id", DEBUG_DEVELOPER);
// FIXME: block position overrides should be merged in with block instance
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment