Make Block Invisible to Teachers - Even in Edit Mode

Make Block Invisible to Teachers - Even in Edit Mode

by Marty Gilbert -
Number of replies: 0
Picture of Core developers

Hi All -

I'm developing a block that should 1) only be added to a course by a site admin and 2) should only be visible to students.

I've conquered #1 through the use of the block/myblock:addinstance capability. Too easy - capabilities, FTW!

I thought I had conquered #2 through the use of a capability check for mod/assign:grade in the block's get_content() method. I simply set $this->content->text = '' and return $this->content. (I've also tried returning null or '' alone, and they seem to act similarly) This works, in that the block content only appears to students.

But here's the rub - when a teacher enables edit mode, not only can they see the block, but they can hide the block, modify the block's configuration, and delete the block!

I've worked around the problem by adjusting the permissions on that block and removing the moodle/block:view capability on that block for teachers, but I want to add this block on a category page and have it persist throughout all courses in that category. Teachers can't delete the block when I do this, but they can still hide and modify the block.

So my question is this: is there any way programmatically, either through capabilities or code in get_content(), that I can hide the block from teachers when they put the course in edit mode?

Thanks in advance,

Marty


Average of ratings: -