MDL-74317 blocks: Blocks can be added to profile pages
- Fixed method user_can_addto to take into account that blocks can also be added to user profile pages
This commit is contained in:
@@ -597,9 +597,20 @@ class block_base {
|
||||
* @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.
|
||||
|
||||
@@ -618,10 +629,12 @@ class block_base {
|
||||
&& 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user