diff --git a/admin/roles/tabs.php b/admin/roles/tabs.php
index bedf5401010..1d37a0dfa4c 100755
--- a/admin/roles/tabs.php
+++ b/admin/roles/tabs.php
@@ -118,54 +118,39 @@ if ($currenttab != 'update') {
break;
case CONTEXT_BLOCK:
- if ($blockinstance = $DB->get_record('block_instance_old', array('oldid'=>$context->instanceid))) {
- if ($block = $DB->get_record('block', array('id'=>$blockinstance->blockid))) {
- $blockname = print_context_name($context);
+ if ($blockinstance = $DB->get_record('block_instances', array('id' => $context->instanceid))) {
+ $blockname = print_context_name($context);
+
+ $parentcontext = get_context_instance_by_id($blockinstance->contextid);
+ $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
+ $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
+ switch ($parentcontext->contextlevel) {
+ case CONTEXT_SYSTEM:
+ break;
+
+ case CONTEXT_COURSECAT:
+ $PAGE->set_category_by_id($parentcontext->instanceid);
+ break;
+
+ case CONTEXT_COURSE:
+ require_login($parentcontext->instanceid);
+ break;
+
+ case CONTEXT_MODULE:
+ $cm = get_coursemodule_from_id('', $parentcontext->instanceid);
+ require_login($parentcontext->instanceid, false, $cm);
+ break;
+
+ case CONTEXT_USER:
+ break;
+
+ default:
+ throw new invalid_state_exception('Block context ' . $blockname .
+ ' has parent context with an improper contextlevel ' . $parentcontext->contextlevel);
- switch ($blockinstance->pagetype) {
- case 'course-view':
- if ($course = $DB->get_record('course', array('id'=>$blockinstance->pageid))) {
-
- require_login($course);
-
- $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
- $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
- $navigation = build_navigation($navlinks);
- print_header("$straction: $blockname", $course->fullname, $navigation);
- }
- break;
-
- case 'blog-view':
- $strblogs = get_string('blogs','blog');
- $navlinks[] = array('name' => $strblogs,
- 'link' => $CFG->wwwroot.'/blog/index.php',
- 'type' => 'misc');
- $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
- $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
- $navigation = build_navigation($navlinks);
- print_header("$straction: $strblogs", $SITE->fullname, $navigation);
- break;
-
- case 'tag-index':
- $strtags = get_string('tags');
- $navlinks[] = array('name' => $strtags,
- 'link' => $CFG->wwwroot.'/tag/index.php',
- 'type' => 'misc');
- $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
- $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
- $navigation = build_navigation($navlinks);
- print_header("$straction: $strtags", $SITE->fullname, $navigation);
- break;
-
- default:
- $navlinks[] = array('name' => $blockname, 'link' => null, 'type' => 'misc');
- $navlinks[] = array('name' => $straction, 'link' => null, 'type' => 'misc');
- $navigation = build_navigation($navlinks);
- print_header("$straction: $blockname", $SITE->fullname, $navigation);
- break;
- }
}
+ print_header("$straction: $blockname", $PAGE->course->fullname, build_navigation($navlinks));
}
break;
diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php
index a92534922ae..72e4eec81b9 100644
--- a/blocks/moodleblock.class.php
+++ b/blocks/moodleblock.class.php
@@ -460,7 +460,8 @@ class block_base {
$movebuttons .= '' .
'
';
- if ($this->user_can_edit()) {
+ // TODO MDL-19010 fix and re-enable.
+ if (false && $this->user_can_edit()) {
$movebuttons .= '';
}
@@ -713,7 +714,7 @@ class block_base {
function instance_config_save($data, $nolongerused = false) {
global $DB;
$DB->set_field('block_instances', 'configdata', base64_encode(serialize($data)),
- array($field => $this->instance->id));
+ array('id' => $this->instance->id));
}
/**
diff --git a/lib/accesslib.php b/lib/accesslib.php
index 01afc631f72..dc2c239d6b3 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -3594,10 +3594,10 @@ function fetch_context_capabilities($context) {
break;
case CONTEXT_BLOCK: // block caps
- $cb = $DB->get_record('block_instances', array('id'=>$context->instanceid));
+ $bi = $DB->get_record('block_instances', array('id' => $context->instanceid));
$extra = '';
- $extracaps = block_method_result($cb->blockname, 'get_extra_capabilities');
+ $extracaps = block_method_result($bi->blockname, 'get_extra_capabilities');
if ($extracaps) {
list($extra, $params) = $DB->get_in_or_equal($extracaps, SQL_PARAMS_NAMED, 'cap0');
$extra = "OR name $extra";
@@ -3608,7 +3608,7 @@ function fetch_context_capabilities($context) {
WHERE (contextlevel = ".CONTEXT_BLOCK."
AND component = :component)
$extra";
- $params['component'] = "block/$block->name";
+ $params['component'] = 'block/' . $bi->blockname;
break;
default:
diff --git a/lib/blocklib.php b/lib/blocklib.php
index 4f6208e317f..11e9225e097 100644
--- a/lib/blocklib.php
+++ b/lib/blocklib.php
@@ -384,6 +384,10 @@ class block_manager implements ArrayAccess {
$blockinstance->configdata = '';
$blockinstance->id = $DB->insert_record('block_instances', $blockinstance);
+ if ($this->page->context->contextlevel == CONTEXT_COURSE) {
+ get_context_instance(CONTEXT_BLOCK, $blockinstance->id);
+ }
+
// If the new instance was created, allow it to do additional setup
if($block = block_instance($blockname, $blockinstance)) {
$block->instance_create();
@@ -872,29 +876,19 @@ function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceori
switch($blockaction) {
case 'config':
- $block = blocks_get_record($instance->blockid);
- // Hacky hacky tricky stuff to get the original human readable block title,
- // even if the block has configured its title to be something else.
- // Create the object WITHOUT instance data.
- $blockobject = block_instance($block->name);
- if ($blockobject === false) {
- break;
- }
-
// First of all check to see if the block wants to be edited
- if(!$blockobject->user_can_edit()) {
+ if(!$instance->user_can_edit()) {
break;
}
// Now get the title and AFTER that load up the instance
- $blocktitle = $blockobject->get_title();
- $blockobject->_load_instance($instance);
+ $blocktitle = $instance->get_title();
// Define the data we're going to silently include in the instance config form here,
// so we can strip them from the submitted data BEFORE serializing it.
$hiddendata = array(
'sesskey' => sesskey(),
- 'instanceid' => $instance->id,
+ 'instanceid' => $instance->instance->id,
'blockaction' => 'config'
);
@@ -906,32 +900,30 @@ function blocks_execute_action($page, &$blockmanager, $blockaction, $instanceori
foreach($remove as $item) {
unset($data->$item);
}
- if(!$blockobject->instance_config_save($data, $pinned)) {
- print_error('cannotsaveblock');
- }
- // And nothing more, continue with displaying the page
- }
- else {
+ $instance->instance_config_save($data);
+ redirect($page->url->out());
+
+ } else {
// We need to show the config screen, so we highjack the display logic and then die
$strheading = get_string('blockconfiga', 'moodle', $blocktitle);
- $page->print_header(get_string('pageheaderconfigablock', 'moodle'), array($strheading => ''));
+ $nav = build_navigation($strheading, $page->cm);
+ print_header($strheading, $strheading, $nav);
- echo '