MDL-73339 core_blocks: New method can_block_be_added
A new method, can_block_be_added, has been added to let blocks override it to decide whether it should be added to a page or not.
This commit is contained in:
@@ -747,6 +747,18 @@ EOD;
|
||||
public function get_aria_role() {
|
||||
return 'complementary';
|
||||
}
|
||||
|
||||
/**
|
||||
* This method can be overriden to add some extra checks to decide whether the block can be added or not to a page.
|
||||
* It doesn't need to do the standard capability checks as they will be performed by has_add_block_capability().
|
||||
* This method is user agnostic. If you want to check if a user can add a block or not, you should use user_can_addto().
|
||||
*
|
||||
* @param moodle_page $page The page where this block will be added.
|
||||
* @return bool Whether the block can be added or not to the given page.
|
||||
*/
|
||||
public function can_block_be_added(moodle_page $page): bool {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -8,6 +8,8 @@ The Quiz results block is hidden by default since Moodle 2.9. It is recommended
|
||||
* External function core_block::get_dashboard_blocks has a new parameter to indicate if you want to receive the block on the my/courses page.
|
||||
* The `core_block_fetch_addable_blocks` external method accepts an optional `subpage` parameter, in order to correctly
|
||||
calculate available blocks for pages that use this property (e.g. the user dashboard)
|
||||
* A new method, can_block_be_added(), has been added to let blocks override it when they want to include some extra checks
|
||||
to decide whether the block can be added to a page or not.
|
||||
|
||||
=== 3.8 ===
|
||||
* Block block_community is no longer a part of core.
|
||||
@@ -108,4 +110,3 @@ required changes in code:
|
||||
* use 'pluginname' lang pack identifier instead of 'blockname'
|
||||
* move cron and version number into standard version.php
|
||||
* removed support for old config_global.html, use settings.php
|
||||
|
||||
|
||||
@@ -223,6 +223,7 @@ class block_manager {
|
||||
}
|
||||
if ($block->visible && !in_array($block->name, $unaddableblocks) &&
|
||||
!in_array($block->name, $requiredbythemeblocks) &&
|
||||
$bi->can_block_be_added($this->page) &&
|
||||
($bi->instance_allow_multiple() || !$this->is_block_present($block->name)) &&
|
||||
blocks_name_allowed_in_format($block->name, $pageformat) &&
|
||||
$bi->user_can_addto($this->page)) {
|
||||
|
||||
Reference in New Issue
Block a user