mirror of
https://github.com/moodle/moodle.git
synced 2025-02-20 08:05:49 +01:00
MDL-49306 blocks: Copy instance data when copying block instances
This commit is contained in:
parent
d8727a4d00
commit
ad5c323065
@ -501,6 +501,15 @@ class block_base {
|
|||||||
return true;
|
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.
|
* Delete everything related to this instance if you have been using persistent storage other than the configdata field.
|
||||||
* @return boolean
|
* @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)
|
* 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.
|
* 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 ===
|
=== 2.8 ===
|
||||||
|
|
||||||
|
@ -81,11 +81,17 @@ function my_copy_page($userid, $private=MY_PAGE_PRIVATE, $pagetype='my-index') {
|
|||||||
'pagetypepattern' => $pagetype,
|
'pagetypepattern' => $pagetype,
|
||||||
'subpagepattern' => $systempage->id));
|
'subpagepattern' => $systempage->id));
|
||||||
foreach ($blockinstances as $instance) {
|
foreach ($blockinstances as $instance) {
|
||||||
|
$originalid = $instance->id;
|
||||||
unset($instance->id);
|
unset($instance->id);
|
||||||
$instance->parentcontextid = $usercontext->id;
|
$instance->parentcontextid = $usercontext->id;
|
||||||
$instance->subpagepattern = $page->id;
|
$instance->subpagepattern = $page->id;
|
||||||
$instance->id = $DB->insert_record('block_instances', $instance);
|
$instance->id = $DB->insert_record('block_instances', $instance);
|
||||||
$blockcontext = context_block::instance($instance->id); // Just creates the context record
|
$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
|
// FIXME: block position overrides should be merged in with block instance
|
||||||
|
Loading…
x
Reference in New Issue
Block a user