Merge branch 'MDL-72278-master' of git://github.com/bmbrands/moodle

This commit is contained in:
Jun Pataleta 2021-10-07 22:48:10 +08:00
commit 74fbe453c7
8 changed files with 56 additions and 4 deletions

View File

@ -382,6 +382,18 @@ class block_manager {
return !empty($this->visibleblockcontent[$region]) || !empty($this->extracontent[$region]);
}
/**
* Determine whether a region contains any fake blocks.
*
* (Fake blocks are typically added to the extracontent array per region)
*
* @param string $region a block region that exists on this page.
* @return boolean Whether there are fake blocks in this region.
*/
public function region_has_fakeblocks($region): bool {
return !empty($this->extracontent[$region]);
}
/**
* Get an array of all of the installed blocks.
*

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -156,6 +156,10 @@ export default class Drawers {
if (this.drawerNode.classList.contains('show')) {
this.openDrawer();
} else if (this.drawerNode.dataset.forceopen == 1) {
if (!isSmall()) {
this.openDrawer();
}
} else {
Aria.hide(this.drawerNode);
}
@ -276,7 +280,7 @@ export default class Drawers {
this.drawerNode.classList.add('show');
const preference = this.drawerNode.dataset.preference;
if (preference) {
if (preference && !isSmall() && (this.drawerNode.dataset.forceopen != 1)) {
M.util.set_user_preference(preference, true);
}

View File

@ -247,4 +247,36 @@ class core_renderer extends \core_renderer {
return $html;
}
/**
* See if this is the first view of the current cm in the session if it has fake blocks.
*
* (We track up to 100 cms so as not to overflow the session.)
* This is done for drawer regions containing fake blocks so we can show blocks automatically.
*
* @return boolean true if the page has fakeblocks and this is the first visit.
*/
public function firstview_fakeblocks(): bool {
global $SESSION;
$firstview = false;
if ($this->page->cm) {
if (!$this->page->blocks->region_has_fakeblocks('side-pre')) {
return false;
}
if (!property_exists($SESSION, 'firstview_fakeblocks')) {
$SESSION->firstview_fakeblocks = [];
}
if (array_key_exists($this->page->cm->id, $SESSION->firstview_fakeblocks)) {
$firstview = false;
} else {
$SESSION->firstview_fakeblocks[$this->page->cm->id] = true;
$firstview = true;
if (count($SESSION->firstview_fakeblocks) > 100) {
array_shift($SESSION->firstview_fakeblocks);
}
}
}
return $firstview;
}
}

View File

@ -64,6 +64,7 @@ if (!$courseindex) {
}
$bodyattributes = $OUTPUT->body_attributes($extraclasses);
$forceblockdraweropen = $OUTPUT->firstview_fakeblocks();
$buildregionmainsettings = !$PAGE->include_region_main_settings_in_header_actions();
// If the settings menu will be included in the header then don't add it here.
@ -98,6 +99,7 @@ $templatecontext = [
'secondarymoremenu' => $secondarynavigation,
'usermenu' => $primarymenu['user'],
'langmenu' => $primarymenu['lang'],
'forceblockdraweropen' => $forceblockdraweropen,
];
$nav = $PAGE->flatnav;

View File

@ -31,6 +31,7 @@
}} id="{{$id}}{{/id}}"{{!
}} data-preference="{{$drawerpreferencename}}{{/drawerpreferencename}}"{{!
}} data-state="{{$drawerstate}}{{/drawerstate}}"{{!
}} data-forceopen="{{$forceopen}}0{{/forceopen}}"{{!
}} data-close-on-resize="{{$drawercloseonreize}}0{{/drawercloseonreize}}"{{!
}}>
<div class="drawerheader">

View File

@ -75,7 +75,7 @@
{{#hasblocks}}
{{< theme_boost/drawer }}
{{$id}}theme_boost-drawers-blocks{{/id}}
{{$drawerclasses}}drawer drawer-right {{#blockdraweropen}}show{{/blockdraweropen}}{{/drawerclasses}}
{{$drawerclasses}}drawer drawer-right{{#blockdraweropen}} show{{/blockdraweropen}}{{/drawerclasses}}
{{$drawerheading}}
{{#str}} blocks {{/str}}
{{/drawerheading}}
@ -85,6 +85,7 @@
</section>
{{/drawercontent}}
{{$drawerpreferencename}}drawer-open-block{{/drawerpreferencename}}
{{$forceopen}}{{#forceblockdraweropen}}1{{/forceblockdraweropen}}{{/forceopen}}
{{$drawerstate}}show-drawer-right{{/drawerstate}}
{{$drawercloseonresize}}1{{/drawercloseonresize}}
{{/ theme_boost/drawer}}