Skip to content

Commit

Permalink
MDL-74317 blocks: Blocks can be added to profile pages
Browse files Browse the repository at this point in the history
- Fixed method user_can_addto to take into account that
blocks can also be added to user profile pages
  • Loading branch information
dravek committed May 2, 2022
1 parent b1a142e commit e1da77a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,20 @@ function user_can_edit() {
* @return boolean
*/
function user_can_addto($page) {
global $CFG;
require_once($CFG->dirroot . '/user/lib.php');

// List of formats this block supports.
$formats = $this->applicable_formats();

// Check if user is trying to add blocks to their profile page.
$userpagetypes = user_page_type_list($page->pagetype, null, null);
if (array_key_exists($page->pagetype, $userpagetypes)) {
$capability = 'block/' . $this->name() . ':addinstance';
return $this->has_add_block_capability($page, $capability)
&& has_capability('moodle/user:manageownblocks', $page->context);
}

// The blocks in My Moodle are a special case and use a different capability.
$mypagetypes = my_page_type_list($page->pagetype); // Get list of possible my page types.

Expand All @@ -618,10 +629,12 @@ function user_can_addto($page) {
&& has_capability('moodle/my:manageblocks', $page->context);
}
}
// Check if this is a block only used on /my.
unset($formats['my']);
// Check if this is a block only used on 'my' or 'user' page types.
foreach (array_keys($mypagetypes + $userpagetypes) as $key) {
unset($formats[$key]);
}
if (empty($formats)) {
// Block can only be added to /my - return false.
// Block can only be added to 'my' or 'user' page types - return false.
return false;
}

Expand Down

0 comments on commit e1da77a

Please sign in to comment.