Skip to content
Browse files

MDL-26881 work around the block context setting problems

  • Loading branch information...
1 parent 92a387b commit ce8b66c67f9ac0122ddf637ce4e37e2f7fe9b61f @skodak skodak committed Mar 27, 2011
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/pagelib.php
View
10 lib/pagelib.php
@@ -762,6 +762,8 @@ public function set_context($context) {
// fine - no change needed
} else if ($this->_context->contextlevel == CONTEXT_SYSTEM or $this->_context->contextlevel == CONTEXT_COURSE) {
// hmm - not ideal, but it might produce too many warnings due to the design of require_login
+ } else if ($this->_context->contextlevel == CONTEXT_MODULE and $this->_context->id == get_parent_contextid($context)) {
+ // hmm - most probably somebody did require_login() and after that set the block context
} else {
// we do not want devs to do weird switching of context levels on the fly,
// because we might have used the context already such as in text filter in page title
@@ -803,8 +805,12 @@ public function set_cm($cm, $course = null, $module = null) {
$cm = $modinfo->get_cm($cm->id);
}
$this->_cm = $cm;
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- $this->set_context($context); // the content of page MUST match the cm, this prints warning if there is any problem
+
+ // unfortunately the context setting is a mess, let's try to work around some common block problems and show some debug messages
+ if (empty($this->_context) or $this->_context->contextlevel != CONTEXT_BLOCK) {
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $this->set_context($context);
+ }
if ($module) {
$this->set_activity_record($module);

0 comments on commit ce8b66c

Please sign in to comment.
Something went wrong with that request. Please try again.