Edwiser课程格式移动端插件在Moodle App中不生效问题排查
问题描述
我正在按照《移动端课程格式插件开发指南》为Moodle App开发Edwiser课程格式(remuiformat)的移动端支持插件,已创建db/mobile.php、classes/output/mobile.php、templates/mobile_course.mustache核心文件,但移动端始终显示默认课程格式(插件不被支持时的 fallback 样式)。切换到flexsections等官方支持的课程格式时,移动端显示正常。
已执行的排查操作:
- 移动端清理站点下载数据(应用设置->存储空间->删除所有站点下载数据)
- 服务器端清除所有缓存
代码文件内容
moodle/course/format/remuiformat/db/mobile.php
<?php $addons = [ 'format_remuiformat' => [ 'handlers' => [ // Different places where the plugin will display content. 'remuiformat' => [ // Handler unique name (alphanumeric). 'delegate' => 'CoreCourseFormatDelegate', // Delegate (where to display the link to the plugin) 'method' => 'mobile_course_view', // Main function in \format_remuiformat\output\mobile. 'styles' => [ 'url' => $CFG->wwwroot . '/course/format/remuiformat/mobile.css', 'version' => 2019041000 ], 'displaysectionselector' => true, // Set to false to disable the default section selector. 'displayenabledownload' => true, // Set to false to hide the "Enable download" option in the course context menu. 'init' => 'remuiformat_init' ] ] ] ];
moodle/course/format/remuiformat/classes/output/mobile.php
<?php class mobile { /** * Main course page. * * @param array $args Standard mobile web service arguments * @return array */ public static function mobile_course_view($args) { global $OUTPUT, $CFG; $course = get_course($args['courseid']); require_login($course); $html = $OUTPUT->render_from_template('format_remuiformat/mobile_course', []); return [ 'templates' => [ [ 'id' => 'main', 'html' => $html ] ], 'otherdata' => '', ]; } }
moodle/course/format/remuiformat/templates/mobile_course.mustache
{{=<% %>=}} <core-dynamic-component [component]="allSectionsComponent" [data]="data" class="format-myformat"> <ng-container *ngFor="let section of sections"> <h1>Test</h1> <ion-item-divider color="light"> <core-format-text [text]="section.name"></core-format-text> <!-- Section download. --> <div *ngIf="section && downloadEnabled" class="core-button-spinner" float-end> <!-- Download button. --> <button *ngIf="section.showDownload && !section.isDownloading && !section.isCalculating" (click)="prefetch($event, section)" ion-button icon-only clear color="dark" [attr.aria-label]="'core.download' | translate"> <ion-icon name="cloud-download"></ion-icon> </button> <!-- Refresh button. --> <button *ngIf="section.showRefresh && !section.isDownloading && !section.isCalculating" (click)="prefetch($event, section)" ion-button icon-only clear color="dark" [attr.aria-label]="'core.refresh' | translate"> <ion-icon name="refresh"></ion-icon> </button> <!-- Download progress. --> <ion-badge class="core-course-download-section-progress" *ngIf="section.isDownloading && section.total > 0 && section.count < section.total">{{section.count}} / {{section.total}}</ion-badge> <!-- Spinner (downloading or calculating status). --> <ion-spinner *ngIf="(section.isDownloading && section.total > 0) || section.isCalculating"></ion-spinner> </div> </ion-item-divider> <ion-item text-wrap *ngIf="section.summary"> <core-format-text [text]="section.summary"></core-format-text> </ion-item> <ng-container *ngFor="let module of section.modules"> <ng-container *ngIf="module.visibleoncoursepage !== 0"> <core-course-module text-wrap [module]="module" [courseId]="course.id" [downloadEnabled]="downloadEnabled" (completionChanged)="onCompletionChange($event)"> </core-course-module> </ng-container> </ng-container> </ng-container> </core-dynamic-component>
排查与解决方向
1. 修复类命名空间缺失问题
Moodle移动端输出类必须放在对应插件的命名空间下,否则无法被系统识别。修改classes/output/mobile.php:
<?php namespace format_remuiformat\output; class mobile { // 原有代码保持不变 }
2. 修正db/mobile.php的配置错误
- 数组闭合括号存在语法问题,需修正
- 若未实现
remuiformat_initJS初始化函数,需移除init参数(否则会导致加载失败)
<?php $addons = [ 'format_remuiformat' => [ 'handlers' => [ 'remuiformat' => [ 'delegate' => 'CoreCourseFormatDelegate', 'method' => 'mobile_course_view', 'styles' => [ 'url' => $CFG->wwwroot . '/course/format/remuiformat/mobile.css', 'version' => 2019041000 ], 'displaysectionselector' => true, 'displayenabledownload' => true ] ] ] ];
注:若无需自定义样式,可直接移除styles节点;若保留,需确保mobile.css文件存在且权限正常。
3. 补充模板渲染所需数据
当前mobile_course_view方法传递给模板的是空数组,导致模板无法渲染有效内容,系统会 fallback 到默认格式。需补充章节、课程状态等数据:
public static function mobile_course_view($args) { global $OUTPUT, $CFG, $USER; $course = get_course($args['courseid']); require_login($course); // 获取课程格式实例与章节数据 $format = course_get_format($course); $sections = $format->get_sections(); // 获取用户离线下载偏好 $downloadenabled = (bool) get_user_preferences('core_course_downloadenable', $CFG->enableoffline); $data = [ 'course' => $course, 'sections' => array_values($sections), 'downloadEnabled' => $downloadenabled ]; $html = $OUTPUT->render_from_template('format_remuiformat/mobile_course', $data); return [ 'templates' => [ [ 'id' => 'main', 'html' => $html ] ], 'otherdata' => '', ]; }
4. 验证插件是否被移动端服务识别
访问Moodle移动端插件清单接口:http://你的Moodle域名/local/mobile/launch.php?addons=1,搜索format_remuiformat:
- 若未找到,说明服务器端配置存在问题,需检查:
- 插件目录名称是否为
remuiformat(必须与插件内部标识一致) db/mobile.php文件权限是否为服务器可读- 插件是否已在站点管理->插件->课程格式中启用
- 插件目录名称是否为
5. 模板语法与一致性修正
- 模板开头的分隔符替换
{{=<% %>=}}可移除(Angular语法无需此配置) - 将类名
format-myformat改为format-remuiformat,保持与插件标识一致性
内容的提问来源于stack exchange,提问作者DesignThala
相关产品推荐
相关产品推荐

