mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-82349 courseformat: add reactivity to frontpage topic
This commit is contained in:
parent
c6a9177252
commit
c5133ddc47
@ -89,6 +89,7 @@ class frontpagesection implements named_templatable, renderable {
|
||||
}
|
||||
|
||||
$data = (object)[
|
||||
'editing' => $format->show_editor(),
|
||||
'sections' => [$sectionoutput->export_for_template($output)],
|
||||
];
|
||||
|
||||
|
@ -51,7 +51,7 @@ class format_site extends course_format {
|
||||
* Returns the display name of the given section that the course prefers.
|
||||
*
|
||||
* @param int|stdClass $section Section object from database or just field section.section
|
||||
* @return Display name that the course format prefers, e.g. "Topic 2"
|
||||
* @return string Display name that the course format prefers, e.g. "Topic 2"
|
||||
*/
|
||||
function get_section_name($section) {
|
||||
$section = $this->get_section($section);
|
||||
@ -88,6 +88,26 @@ class format_site extends course_format {
|
||||
return blocks_get_default_site_course_blocks();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function supports_ajax() {
|
||||
// All home page is rendered in the backend, we only need an ajax editor components in edit mode.
|
||||
// This will also prevent redirectng to the login page when a guest tries to access the site,
|
||||
// and will make the home page loading faster.
|
||||
$ajaxsupport = new stdClass();
|
||||
$ajaxsupport->capable = $this->show_editor();
|
||||
return $ajaxsupport;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function supports_components() {
|
||||
return true;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function uses_sections() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Definitions of the additional options that site uses
|
||||
*
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"editing": true,
|
||||
"sections": [
|
||||
"<li>This is the section content</li>"
|
||||
],
|
||||
@ -28,7 +29,7 @@
|
||||
"settingsurl": "#"
|
||||
}
|
||||
}}
|
||||
<div class="course-content">
|
||||
<div class="course-content" id="courseformat-frontpage-main-topic">
|
||||
{{#showsettings}}
|
||||
<div class="mb-2">
|
||||
<a href="{{{settingsurl}}}" title="{{#str}} edit {{/str}}" aria-label="{{#str}} edit {{/str}}">
|
||||
@ -37,10 +38,18 @@
|
||||
</div>
|
||||
{{/showsettings}}
|
||||
<div class="sitetopic">
|
||||
<ul class="topics frontpage">
|
||||
<ul class="topics frontpage" data-for="course_sectionlist">
|
||||
{{#sections}}
|
||||
{{> core_courseformat/local/content/section }}
|
||||
{{/sections}}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
{{#js}}
|
||||
{{! The home page should be as fast as possible, we only load the editor when needed.}}
|
||||
{{#editing}}
|
||||
require(['core_courseformat/local/content'], function(component) {
|
||||
component.init('courseformat-frontpage-main-topic', {});
|
||||
});
|
||||
{{/editing}}
|
||||
{{/js}}
|
||||
|
@ -2867,7 +2867,7 @@ function include_course_editor(course_format $format) {
|
||||
|
||||
$course = $format->get_course();
|
||||
|
||||
if ($SITE->id === $course->id) {
|
||||
if (!$format->supports_ajax()?->capable) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
14
index.php
14
index.php
@ -109,6 +109,14 @@ $PAGE->set_title(get_string('home'));
|
||||
$PAGE->set_heading($SITE->fullname);
|
||||
$PAGE->set_secondary_active_tab('coursehome');
|
||||
|
||||
$siteformatoptions = course_get_format($SITE)->get_format_options();
|
||||
$modinfo = get_fast_modinfo($SITE);
|
||||
$modnamesused = $modinfo->get_used_module_names();
|
||||
|
||||
// The home page can have acitvities in the block aside. We should
|
||||
// initialize the course editor before the page structure is rendered.
|
||||
include_course_ajax($SITE, $modnamesused);
|
||||
|
||||
$courserenderer = $PAGE->get_renderer('core', 'course');
|
||||
|
||||
if ($hassiteconfig) {
|
||||
@ -119,10 +127,6 @@ if ($hassiteconfig) {
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
$siteformatoptions = course_get_format($SITE)->get_format_options();
|
||||
$modinfo = get_fast_modinfo($SITE);
|
||||
$modnamesused = $modinfo->get_used_module_names();
|
||||
|
||||
// Print Section or custom info.
|
||||
if (!empty($CFG->customfrontpageinclude)) {
|
||||
// Pre-fill some variables that custom front page might use.
|
||||
@ -135,8 +139,6 @@ if (!empty($CFG->customfrontpageinclude)) {
|
||||
} else if ($siteformatoptions['numsections'] > 0) {
|
||||
echo $courserenderer->frontpage_section1();
|
||||
}
|
||||
// Include course AJAX.
|
||||
include_course_ajax($SITE, $modnamesused);
|
||||
|
||||
echo $courserenderer->frontpage();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user