Context of a block inside "my" page.

Re: Context of a block inside "my" page.

by jon sharp -
Number of replies: 0

There is a problem with this when editing user-specific settings for the block when on my page.

You can add the fields in specific_definition($mform), but blocks/edit_from.php does:

if (!$this->block->user_can_edit()) {
            $mform->hardFreezeAllVisibleExcept($pagefields);
}

which sadly does 'freeze' the fields from editing, as user_can_edit() does:

if (!empty($USER->id)
            && $this->instance->parentcontextid == $this->page->context->id   // Block belongs to this page
            && $this->page->context->contextlevel == CONTEXT_USER             // Page belongs to a user
            && $this->page->context->instanceid == $USER->id) {               // Page belongs to this user
            return has_capability('moodle/my:manageblocks', $this->page->context);
 }

and $this->instance->parentcontextid == $this->page->context->id   seems always to be unequal

$this->page->context->id is set to users context id, and $this->instance->parentcontextid is 1

Commenting this line out allows the input fields to be rendered.

Ref: https://docs.moodle.org/dev/Blocks/Appendix_A#.24this-.3Econtext '$this->context' para.

Not sure how to configure / code the block to get these to be equal?

This is in M3.0.3 - I think it worked in M2.6.