mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
Changing the way that applicable formats for each block are defined:
The format for each page is now the same as the id attribute of the BODY tag, which in turn is a simple function of the script's relative path: The format for e.g. a quiz view page is "mod-quiz-view". The format for the site index is "site-index". Exception: the format for courses is not just "course-view", but "course-view-weeks" etc. Obviously the applicable_formats() override for each block should now take this into account. The matching rules now are: * You can specify the full format, e.g. "mod-quiz-view" => true will allow the block to be added in quizzes * Prefixes match the full page format, e.g. "mod" matches ALL activities * You can use "*" as a wildcard, e.g. "mod-*-view" matches just the view.php page of all activities * These rules interoperate, thus "mod-*" is the same as "mod" * "all" remains as a catch-all situation
This commit is contained in:
parent
bb64b51aa3
commit
8a47e075b3
5 changed files with 38 additions and 23 deletions
|
@ -103,8 +103,20 @@ function blocks_get_missing(&$page, &$pageblocks) {
|
|||
if($block->visible && (!blocks_find_block($block->id, $pageblocks) || $block->multiple)) {
|
||||
// And if it's applicable for display in this format...
|
||||
$formats = block_method_result($block->name, 'applicable_formats');
|
||||
if(isset($formats[$pageformat]) ? $formats[$pageformat] : !empty($formats['all'])) {
|
||||
// Add it to the missing blocks
|
||||
$accept = NULL;
|
||||
foreach($formats as $format => $allowed) {
|
||||
$thisformat = '^'.str_replace('*', '[^-]*', $format).'.*$';
|
||||
if(ereg($thisformat, $pageformat)) {
|
||||
$accept = $allowed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($accept === NULL) {
|
||||
// ...or in all pages...
|
||||
$accept = !empty($formats['all']);
|
||||
}
|
||||
if(!empty($accept)) {
|
||||
// ...add it to the missing blocks
|
||||
$missingblocks[] = $block->id;
|
||||
}
|
||||
}
|
||||
|
@ -128,12 +140,19 @@ function blocks_remove_inappropriate($page) {
|
|||
foreach($position as $instance) {
|
||||
$block = blocks_get_record($instance->blockid);
|
||||
$formats = block_method_result($block->name, 'applicable_formats');
|
||||
if(! (isset($formats[$pageformat]) ? $formats[$pageformat] : !empty($formats['all']))) {
|
||||
// Translation: if the course format is explicitly accepted/rejected, use
|
||||
// that setting. Otherwise, fallback to the 'all' format. The empty() test
|
||||
// uses the trick that empty() fails if 'all' is either !isset() or false.
|
||||
|
||||
blocks_delete_instance($instance);
|
||||
$accept = NULL;
|
||||
foreach($formats as $format => $allowed) {
|
||||
$thisformat = '^'.str_replace('*', '[^-]*', $format).'.*$';
|
||||
if(ereg($thisformat, $pageformat)) {
|
||||
$accept = $allowed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if($accept === NULL) {
|
||||
$accept = !empty($formats['all']);
|
||||
}
|
||||
if(empty($accept)) {
|
||||
blocks_delete_instance($instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue