Merge pull request #2902 from dpalou/MOBILE-3688

MOBILE-3688 siteplugins: Auto create mod index&list link handlers
main
Pau Ferrer Ocaña 2021-07-29 10:53:31 +02:00 committed by GitHub
commit 505063710c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 6 deletions

View File

@ -125,9 +125,7 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp
} }
// Check if the plugin specifies if FEATURE_NO_VIEW_LINK is supported. // Check if the plugin specifies if FEATURE_NO_VIEW_LINK is supported.
const noViewLink = <boolean | undefined> (this.supportsFeature ? const noViewLink = this.supportsNoViewLink();
this.supportsFeature(CoreConstants.FEATURE_NO_VIEW_LINK) :
this.supportedFeatures?.[CoreConstants.FEATURE_NO_VIEW_LINK]);
if (noViewLink !== undefined) { if (noViewLink !== undefined) {
return noViewLink; return noViewLink;
@ -137,6 +135,17 @@ export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler imp
return 'noviewlink' in module && !!module.noviewlink; 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 <boolean | undefined> (this.supportsFeature ?
this.supportsFeature(CoreConstants.FEATURE_NO_VIEW_LINK) :
this.supportedFeatures?.[CoreConstants.FEATURE_NO_VIEW_LINK]);
}
/** /**
* Load and use template for course page. * Load and use template for course page.
* *

View File

@ -81,6 +81,9 @@ import { CoreMainMenuHomeDelegate } from '@features/mainmenu/services/home-deleg
import { CoreSitePluginsMainMenuHomeHandler } from '../classes/handlers/main-menu-home-handler'; import { CoreSitePluginsMainMenuHomeHandler } from '../classes/handlers/main-menu-home-handler';
import { AddonWorkshopAssessmentStrategyDelegate } from '@addons/mod/workshop/services/assessment-strategy-delegate'; import { AddonWorkshopAssessmentStrategyDelegate } from '@addons/mod/workshop/services/assessment-strategy-delegate';
import { CoreSitePluginsWorkshopAssessmentStrategyHandler } from '../classes/handlers/workshop-assessment-strategy-handler'; 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'; const HANDLER_DISABLED = 'core_site_plugins_helper_handler_disabled';
@ -886,9 +889,8 @@ export class CoreSitePluginsHelperProvider {
const uniqueName = CoreSitePlugins.getHandlerUniqueName(plugin, handlerName); const uniqueName = CoreSitePlugins.getHandlerUniqueName(plugin, handlerName);
const modName = (handlerSchema.moodlecomponent || plugin.component).replace('mod_', ''); const modName = (handlerSchema.moodlecomponent || plugin.component).replace('mod_', '');
CoreCourseModuleDelegate.registerHandler( const moduleHandler = new CoreSitePluginsModuleHandler(uniqueName, modName, plugin, handlerSchema, initResult);
new CoreSitePluginsModuleHandler(uniqueName, modName, plugin, handlerSchema, initResult), CoreCourseModuleDelegate.registerHandler(moduleHandler);
);
if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) { if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) {
// Register the prefetch handler. // 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; return uniqueName;
} }

View File

@ -846,6 +846,7 @@ export type CoreSitePluginsCourseModuleHandlerData = CoreSitePluginsHandlerCommo
ptrenabled?: boolean; ptrenabled?: boolean;
supportedfeatures?: Record<string, unknown>; supportedfeatures?: Record<string, unknown>;
manualcompletionalwaysshown?: boolean; manualcompletionalwaysshown?: boolean;
nolinkhandlers?: boolean;
}; };
/** /**