From f019c9383765bc18c335c937c139d731fb3938bb Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 29 Jul 2021 08:18:07 +0200 Subject: [PATCH] MOBILE-3688 siteplugins: Auto create mod index&list link handlers --- .../classes/handlers/module-handler.ts | 15 ++++++++++--- .../services/siteplugins-helper.ts | 21 ++++++++++++++++--- .../siteplugins/services/siteplugins.ts | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/core/features/siteplugins/classes/handlers/module-handler.ts b/src/core/features/siteplugins/classes/handlers/module-handler.ts index c776e722c..ee3ae05b6 100644 --- a/src/core/features/siteplugins/classes/handlers/module-handler.ts +++ b/src/core/features/siteplugins/classes/handlers/module-handler.ts @@ -125,9 +125,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp } // 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]); + const noViewLink = this.supportsNoViewLink(); if (noViewLink !== undefined) { return noViewLink; @@ -137,6 +135,17 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp return 'noviewlink' in module && !!module.noviewlink; } + /** + * Check whether the module supports NO_VIEW_LINK. + * + * @return Bool if defined, undefined if not specified. + */ + supportsNoViewLink(): boolean | undefined { + return (this.supportsFeature ? + this.supportsFeature(CoreConstants.FEATURE_NO_VIEW_LINK) : + this.supportedFeatures?.[CoreConstants.FEATURE_NO_VIEW_LINK]); + } + /** * Load and use template for course page. * diff --git a/src/core/features/siteplugins/services/siteplugins-helper.ts b/src/core/features/siteplugins/services/siteplugins-helper.ts index 84a1b626b..3ce97bba9 100644 --- a/src/core/features/siteplugins/services/siteplugins-helper.ts +++ b/src/core/features/siteplugins/services/siteplugins-helper.ts @@ -81,6 +81,9 @@ import { CoreMainMenuHomeDelegate } from '@features/mainmenu/services/home-deleg import { CoreSitePluginsMainMenuHomeHandler } from '../classes/handlers/main-menu-home-handler'; import { AddonWorkshopAssessmentStrategyDelegate } from '@addons/mod/workshop/services/assessment-strategy-delegate'; import { CoreSitePluginsWorkshopAssessmentStrategyHandler } from '../classes/handlers/workshop-assessment-strategy-handler'; +import { CoreContentLinksModuleIndexHandler } from '@features/contentlinks/classes/module-index-handler'; +import { CoreContentLinksDelegate } from '@features/contentlinks/services/contentlinks-delegate'; +import { CoreContentLinksModuleListHandler } from '@features/contentlinks/classes/module-list-handler'; const HANDLER_DISABLED = 'core_site_plugins_helper_handler_disabled'; @@ -886,9 +889,8 @@ export class CoreSitePluginsHelperProvider { const uniqueName = CoreSitePlugins.getHandlerUniqueName(plugin, handlerName); const modName = (handlerSchema.moodlecomponent || plugin.component).replace('mod_', ''); - CoreCourseModuleDelegate.registerHandler( - new CoreSitePluginsModuleHandler(uniqueName, modName, plugin, handlerSchema, initResult), - ); + const moduleHandler = new CoreSitePluginsModuleHandler(uniqueName, modName, plugin, handlerSchema, initResult); + CoreCourseModuleDelegate.registerHandler(moduleHandler); if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) { // Register the prefetch handler. @@ -897,6 +899,19 @@ export class CoreSitePluginsHelperProvider { ); } + // Create default link handlers if needed. + if (!moduleHandler.supportsNoViewLink() && handlerSchema.method && !handlerSchema.nolinkhandlers) { + const indexLinkHandler = new CoreContentLinksModuleIndexHandler(uniqueName, modName); + indexLinkHandler.name = uniqueName + '_indexlink'; + indexLinkHandler.priority = -1; // Use -1 to give more priority to the plugins link handlers if any. + CoreContentLinksDelegate.registerHandler(indexLinkHandler); + + const listLinkHandler = new CoreContentLinksModuleListHandler(uniqueName, modName); + listLinkHandler.name = uniqueName + '_listlink'; + listLinkHandler.priority = -1; // Use -1 to give more priority to the plugins link handlers if any. + CoreContentLinksDelegate.registerHandler(listLinkHandler); + } + return uniqueName; } diff --git a/src/core/features/siteplugins/services/siteplugins.ts b/src/core/features/siteplugins/services/siteplugins.ts index bc7a572b5..e0aa2e9d5 100644 --- a/src/core/features/siteplugins/services/siteplugins.ts +++ b/src/core/features/siteplugins/services/siteplugins.ts @@ -846,6 +846,7 @@ export type CoreSitePluginsCourseModuleHandlerData = CoreSitePluginsHandlerCommo ptrenabled?: boolean; supportedfeatures?: Record; manualcompletionalwaysshown?: boolean; + nolinkhandlers?: boolean; }; /**