From 65e3d39991000582691d00f392cb0de3ce6fc8f4 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 11 May 2021 16:43:47 +0200 Subject: [PATCH] MOBILE-3320 siteplugins: Allow overriding FEATURE_NO_VIEW_LINK --- .../classes/handlers/module-handler.ts | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/core/features/siteplugins/classes/handlers/module-handler.ts b/src/core/features/siteplugins/classes/handlers/module-handler.ts index 11009129f..3293a309e 100644 --- a/src/core/features/siteplugins/classes/handlers/module-handler.ts +++ b/src/core/features/siteplugins/classes/handlers/module-handler.ts @@ -14,6 +14,7 @@ import { Type } from '@angular/core'; +import { CoreConstants } from '@/core/constants'; import { CoreCourseAnyModuleData, CoreCourseWSModule } from '@features/course/services/course'; import { CoreCourseModule } from '@features/course/services/course-helper'; import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@features/course/services/module-delegate'; @@ -65,10 +66,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp sectionId?: number, forCoursePage?: boolean, ): CoreCourseModuleHandlerData { - const callMethod = forCoursePage && this.handlerSchema.coursepagemethod; - - if ('noviewlink' in module && module.noviewlink && !callMethod) { - // The module doesn't link to a new page (similar to label). Only display the description. + if ('description' in module && this.shouldOnlyDisplayDescription(module, forCoursePage)) { const title = module.description; module.description = ''; @@ -105,7 +103,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp }; } - if (callMethod && module.visibleoncoursepage !== 0) { + if (forCoursePage && this.handlerSchema.coursepagemethod && module.visibleoncoursepage !== 0) { // Call the method to get the course page template. this.loadCoursePageTemplate(module, courseId, handlerData); } @@ -113,6 +111,32 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp return handlerData; } + /** + * Check whether the plugin should only display the description, similar to mod_label. + * + * @param module Module. + * @param forCoursePage Whether the data will be used to render the course page. + * @return Bool. + */ + protected shouldOnlyDisplayDescription(module: CoreCourseAnyModuleData, forCoursePage?: boolean): boolean { + if (forCoursePage && this.handlerSchema.coursepagemethod) { + // The plugin defines a method for course page, don't display just the description. + return false; + } + + // Check if the plugin specifies if FEATURE_NO_VIEW_LINK is supported. + const noViewLink = (this.supportsFeature ? + this.supportsFeature(CoreConstants.FEATURE_NO_VIEW_LINK) : + this.supportedFeatures?.[CoreConstants.FEATURE_NO_VIEW_LINK]); + + if (noViewLink !== undefined) { + return noViewLink; + } + + // The plugin doesn't specify it. Use the value returned by the site. + return 'noviewlink' in module && !!module.noviewlink; + } + /** * Load and use template for course page. *