Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Talk:Blocks Advanced

From MoodleDocs

Looking at this recent change: https://docs.moodle.org/dev/index.php?title=Blocks_Advanced&curid=3917&diff=33648&oldid=33236 I am pretty sure the explicit mention of context_course is wrong. For any block, there are three significant contexts:

  1. The block context. ($this->context in the block class. context_block::instance($blockinstance->id))
  2. The block's parent context, that is the place where the block was added. (context::instance_by_id($blockinstance->parentcontextid))
  3. The context of the page the block is currently shown on. ($this->page->context in the block class).

1. is always a direct child of 2. Context 2. will be the same as 3. unless this is a sticky block, in which case 3. will be a descendant of 2. Those are the only three contexts you should ever need to refer to. So, I don't know what the example code is doing, but it looks like a bad example.--Tim Hunt 16:13, 3 May 2012 (WST)