MOBILE-2391 core: Use different property for modName/etc in delegates

main
Dani Palou 2018-03-23 13:24:31 +01:00
parent c1cf6e5b21
commit 0b52f98960
33 changed files with 111 additions and 43 deletions

View File

@ -24,7 +24,8 @@ import { CoreCourseProvider } from '@core/course/providers/course';
*/ */
@Injectable() @Injectable()
export class AddonModBookModuleHandler implements CoreCourseModuleHandler { export class AddonModBookModuleHandler implements CoreCourseModuleHandler {
name = 'book'; name = 'AddonModBook';
modName = 'book';
constructor(protected bookProvider: AddonModBookProvider, private courseProvider: CoreCourseProvider) { } constructor(protected bookProvider: AddonModBookProvider, private courseProvider: CoreCourseProvider) { }

View File

@ -21,7 +21,8 @@ import { AddonModBookProvider } from './book';
*/ */
@Injectable() @Injectable()
export class AddonModBookPrefetchHandler extends CoreCourseModulePrefetchHandlerBase { export class AddonModBookPrefetchHandler extends CoreCourseModulePrefetchHandlerBase {
name = 'book'; name = 'AddonModBook';
modName = 'book';
component = AddonModBookProvider.COMPONENT; component = AddonModBookProvider.COMPONENT;
updatesNames = /^configuration$|^.*files$|^entries$/; updatesNames = /^configuration$|^.*files$|^entries$/;
isResource = true; isResource = true;

View File

@ -23,7 +23,8 @@ import { CoreCourseProvider } from '@core/course/providers/course';
*/ */
@Injectable() @Injectable()
export class AddonModFolderModuleHandler implements CoreCourseModuleHandler { export class AddonModFolderModuleHandler implements CoreCourseModuleHandler {
name = 'folder'; name = 'AddonModFolder';
modName = 'folder';
constructor(private courseProvider: CoreCourseProvider) { } constructor(private courseProvider: CoreCourseProvider) { }

View File

@ -21,7 +21,8 @@ import { AddonModFolderProvider } from './folder';
*/ */
@Injectable() @Injectable()
export class AddonModFolderPrefetchHandler extends CoreCourseModulePrefetchHandlerBase { export class AddonModFolderPrefetchHandler extends CoreCourseModulePrefetchHandlerBase {
name = 'folder'; name = 'AddonModFolder';
modName = 'folder';
component = AddonModFolderProvider.COMPONENT; component = AddonModFolderProvider.COMPONENT;
isResource = true; isResource = true;

View File

@ -20,7 +20,8 @@ import { CoreCourseModuleHandler, CoreCourseModuleHandlerData } from '@core/cour
*/ */
@Injectable() @Injectable()
export class AddonModLabelModuleHandler implements CoreCourseModuleHandler { export class AddonModLabelModuleHandler implements CoreCourseModuleHandler {
name = 'label'; name = 'AddonModLabel';
modName = 'label';
constructor() { constructor() {
// Nothing to do. // Nothing to do.

View File

@ -24,7 +24,8 @@ import { CoreCourseProvider } from '@core/course/providers/course';
*/ */
@Injectable() @Injectable()
export class AddonModPageModuleHandler implements CoreCourseModuleHandler { export class AddonModPageModuleHandler implements CoreCourseModuleHandler {
name = 'page'; name = 'AddonModPage';
modName = 'page';
constructor(private courseProvider: CoreCourseProvider, protected pageProvider: AddonModPageProvider) { } constructor(private courseProvider: CoreCourseProvider, protected pageProvider: AddonModPageProvider) { }

View File

@ -23,7 +23,8 @@ import { AddonModPageHelperProvider } from './helper';
*/ */
@Injectable() @Injectable()
export class AddonModPagePrefetchHandler extends CoreCourseModulePrefetchHandlerBase { export class AddonModPagePrefetchHandler extends CoreCourseModulePrefetchHandlerBase {
name = 'page'; name = 'AddonModPage';
modName = 'page';
component = AddonModPageProvider.COMPONENT; component = AddonModPageProvider.COMPONENT;
updatesNames = /^configuration$|^.*files$/; updatesNames = /^configuration$|^.*files$/;
isResource = true; isResource = true;

View File

@ -26,7 +26,8 @@ import { CoreMimetypeUtilsProvider } from '@providers/utils/mimetype';
*/ */
@Injectable() @Injectable()
export class AddonModResourceModuleHandler implements CoreCourseModuleHandler { export class AddonModResourceModuleHandler implements CoreCourseModuleHandler {
name = 'resource'; name = 'AddonModResource';
modName = 'resource';
constructor(protected resourceProvider: AddonModResourceProvider, private courseProvider: CoreCourseProvider, constructor(protected resourceProvider: AddonModResourceProvider, private courseProvider: CoreCourseProvider,
protected mimetypeUtils: CoreMimetypeUtilsProvider, private resourceHelper: AddonModResourceHelperProvider) { } protected mimetypeUtils: CoreMimetypeUtilsProvider, private resourceHelper: AddonModResourceHelperProvider) { }

View File

@ -23,7 +23,8 @@ import { CoreFilepoolProvider } from '@providers/filepool';
*/ */
@Injectable() @Injectable()
export class AddonModResourcePrefetchHandler extends CoreCourseModulePrefetchHandlerBase { export class AddonModResourcePrefetchHandler extends CoreCourseModulePrefetchHandlerBase {
name = 'resource'; name = 'AddonModResource';
modName = 'resource';
component = AddonModResourceProvider.COMPONENT; component = AddonModResourceProvider.COMPONENT;
isResource = true; isResource = true;

View File

@ -23,7 +23,8 @@ import { CoreCourseProvider } from '@core/course/providers/course';
*/ */
@Injectable() @Injectable()
export class AddonModSurveyModuleHandler implements CoreCourseModuleHandler { export class AddonModSurveyModuleHandler implements CoreCourseModuleHandler {
name = 'survey'; name = 'AddonModSurvey';
modName = 'survey';
constructor(private courseProvider: CoreCourseProvider) { } constructor(private courseProvider: CoreCourseProvider) { }

View File

@ -22,7 +22,8 @@ import { AddonModSurveyHelperProvider } from './helper';
*/ */
@Injectable() @Injectable()
export class AddonModSurveyPrefetchHandler extends CoreCourseModulePrefetchHandlerBase { export class AddonModSurveyPrefetchHandler extends CoreCourseModulePrefetchHandlerBase {
name = 'survey'; name = 'AddonModSurvey';
modName = 'survey';
component = AddonModSurveyProvider.COMPONENT; component = AddonModSurveyProvider.COMPONENT;
updatesNames = /^configuration$|^.*files$|^answers$/; updatesNames = /^configuration$|^.*files$|^answers$/;

View File

@ -25,7 +25,8 @@ import { AddonModUrlHelperProvider } from './helper';
*/ */
@Injectable() @Injectable()
export class AddonModUrlModuleHandler implements CoreCourseModuleHandler { export class AddonModUrlModuleHandler implements CoreCourseModuleHandler {
name = 'url'; name = 'AddonModUrl';
modName = 'url';
constructor(private courseProvider: CoreCourseProvider, private urlProvider: AddonModUrlProvider, constructor(private courseProvider: CoreCourseProvider, private urlProvider: AddonModUrlProvider,
private urlHelper: AddonModUrlHelperProvider) { } private urlHelper: AddonModUrlHelperProvider) { }

View File

@ -21,7 +21,8 @@ import { AddonUserProfileFieldCheckboxComponent } from '../component/checkbox';
*/ */
@Injectable() @Injectable()
export class AddonUserProfileFieldCheckboxHandler implements CoreUserProfileFieldHandler { export class AddonUserProfileFieldCheckboxHandler implements CoreUserProfileFieldHandler {
name = 'checkbox'; name = 'AddonUserProfileFieldCheckbox';
type = 'checkbox';
constructor() { constructor() {
// Nothing to do. // Nothing to do.

View File

@ -21,7 +21,8 @@ import { AddonUserProfileFieldDatetimeComponent } from '../component/datetime';
*/ */
@Injectable() @Injectable()
export class AddonUserProfileFieldDatetimeHandler implements CoreUserProfileFieldHandler { export class AddonUserProfileFieldDatetimeHandler implements CoreUserProfileFieldHandler {
name = 'datetime'; name = 'AddonUserProfileFieldDatetime';
type = 'datetime';
constructor() { constructor() {
// Nothing to do. // Nothing to do.

View File

@ -21,7 +21,8 @@ import { AddonUserProfileFieldMenuComponent } from '../component/menu';
*/ */
@Injectable() @Injectable()
export class AddonUserProfileFieldMenuHandler implements CoreUserProfileFieldHandler { export class AddonUserProfileFieldMenuHandler implements CoreUserProfileFieldHandler {
name = 'menu'; name = 'AddonUserProfileFieldMenu';
type = 'menu';
constructor() { constructor() {
// Nothing to do. // Nothing to do.

View File

@ -22,7 +22,8 @@ import { CoreTextUtilsProvider } from '@providers/utils/text';
*/ */
@Injectable() @Injectable()
export class AddonUserProfileFieldTextHandler implements CoreUserProfileFieldHandler { export class AddonUserProfileFieldTextHandler implements CoreUserProfileFieldHandler {
name = 'text'; name = 'AddonUserProfileFieldText';
type = 'text';
constructor(private textUtils: CoreTextUtilsProvider) { } constructor(private textUtils: CoreTextUtilsProvider) { }

View File

@ -22,7 +22,8 @@ import { CoreTextUtilsProvider } from '@providers/utils/text';
*/ */
@Injectable() @Injectable()
export class AddonUserProfileFieldTextareaHandler implements CoreUserProfileFieldHandler { export class AddonUserProfileFieldTextareaHandler implements CoreUserProfileFieldHandler {
name = 'textarea'; name = 'AddonUserProfileFieldTextarea';
type = 'textarea';
constructor(private textUtils: CoreTextUtilsProvider) { } constructor(private textUtils: CoreTextUtilsProvider) { }

View File

@ -20,6 +20,7 @@ import { CoreEventsProvider } from '@providers/events';
export interface CoreDelegateHandler { export interface CoreDelegateHandler {
/** /**
* Name of the handler, or name and sub context (AddonMessages, AddonMessages:blockContact, ...). * Name of the handler, or name and sub context (AddonMessages, AddonMessages:blockContact, ...).
* This name will be used to check if the feature is disabled.
* @type {string} * @type {string}
*/ */
name: string; name: string;
@ -74,6 +75,14 @@ export class CoreDelegate {
*/ */
protected featurePrefix: string; protected featurePrefix: string;
/**
* Name of the property to be used to index the handlers. By default, the handler's name will be used.
* If your delegate uses a Moodle component name to identify the handlers, please override this property.
* E.g. CoreCourseModuleDelegate uses 'modName' to index the handlers.
* @type {string}
*/
protected handlerNameProperty = 'name';
/** /**
* Constructor of the Delegate. * Constructor of the Delegate.
* *
@ -182,14 +191,14 @@ export class CoreDelegate {
* @return {boolean} True when registered, false if already registered. * @return {boolean} True when registered, false if already registered.
*/ */
registerHandler(handler: CoreDelegateHandler): boolean { registerHandler(handler: CoreDelegateHandler): boolean {
if (typeof this.handlers[handler.name] !== 'undefined') { if (typeof this.handlers[handler[this.handlerNameProperty]] !== 'undefined') {
this.logger.log(`Addon '${handler.name}' already registered`); this.logger.log(`Handler '${handler[this.handlerNameProperty]}' already registered`);
return false; return false;
} }
this.logger.log(`Registered addon '${handler.name}'`); this.logger.log(`Registered handler '${handler[this.handlerNameProperty]}'`);
this.handlers[handler.name] = handler; this.handlers[handler[this.handlerNameProperty]] = handler;
return true; return true;
} }
@ -222,9 +231,9 @@ export class CoreDelegate {
// Check that site hasn't changed since the check started. // Check that site hasn't changed since the check started.
if (this.isLastUpdateCall(time) && this.sitesProvider.getCurrentSiteId() === siteId) { if (this.isLastUpdateCall(time) && this.sitesProvider.getCurrentSiteId() === siteId) {
if (enabled) { if (enabled) {
this.enabledHandlers[handler.name] = handler; this.enabledHandlers[handler[this.handlerNameProperty]] = handler;
} else { } else {
delete this.enabledHandlers[handler.name]; delete this.enabledHandlers[handler[this.handlerNameProperty]];
} }
} }
}); });

View File

@ -53,11 +53,17 @@ export type prefetchFunction = (module: any, courseId: number, single: boolean,
* recommended to call the prefetchPackage function since it'll handle changing the status of the module. * recommended to call the prefetchPackage function since it'll handle changing the status of the module.
*/ */
export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePrefetchHandler { export class CoreCourseModulePrefetchHandlerBase implements CoreCourseModulePrefetchHandler {
/**
* Name of the handler.
* @type {string}
*/
name = 'CoreCourseModulePrefetchHandler';
/** /**
* Name of the module. It should match the "modname" of the module returned in core_course_get_contents. * Name of the module. It should match the "modname" of the module returned in core_course_get_contents.
* @type {string} * @type {string}
*/ */
name = ''; modName = 'default';
/** /**
* The handler's component. * The handler's component.

View File

@ -21,7 +21,8 @@ import { CoreCourseFormatSingleActivityComponent } from '../components/singleact
*/ */
@Injectable() @Injectable()
export class CoreCourseFormatSingleActivityHandler implements CoreCourseFormatHandler { export class CoreCourseFormatSingleActivityHandler implements CoreCourseFormatHandler {
name = 'singleactivity'; name = 'CoreCourseFormatSingleActivity';
format = 'singleactivity';
constructor() { constructor() {
// Nothing to do. // Nothing to do.

View File

@ -21,5 +21,6 @@ import { CoreCourseFormatSingleActivityHandler } from '../../singleactivity/prov
*/ */
@Injectable() @Injectable()
export class CoreCourseFormatSocialHandler extends CoreCourseFormatSingleActivityHandler { export class CoreCourseFormatSocialHandler extends CoreCourseFormatSingleActivityHandler {
name = 'social'; name = 'CoreCourseFormatSocial';
format = 'social';
} }

View File

@ -20,7 +20,8 @@ import { CoreCourseFormatHandler } from '../../../providers/format-delegate';
*/ */
@Injectable() @Injectable()
export class CoreCourseFormatTopicsHandler implements CoreCourseFormatHandler { export class CoreCourseFormatTopicsHandler implements CoreCourseFormatHandler {
name = 'topics'; name = 'CoreCourseFormatTopics';
format = 'topics';
constructor() { constructor() {
// Nothing to do. // Nothing to do.

View File

@ -22,7 +22,8 @@ import { CoreConstants } from '../../../../constants';
*/ */
@Injectable() @Injectable()
export class CoreCourseFormatWeeksHandler implements CoreCourseFormatHandler { export class CoreCourseFormatWeeksHandler implements CoreCourseFormatHandler {
name = 'weeks'; name = 'CoreCourseFormatWeeks';
format = 'weeks';
constructor(private timeUtils: CoreTimeUtilsProvider) { } constructor(private timeUtils: CoreTimeUtilsProvider) { }

View File

@ -23,7 +23,8 @@ import { CoreCourseProvider } from './course';
*/ */
@Injectable() @Injectable()
export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler { export class CoreCourseFormatDefaultHandler implements CoreCourseFormatHandler {
name = 'default'; name = 'CoreCourseFormatDefault';
format = 'default';
constructor(private coursesProvider: CoreCoursesProvider) { } constructor(private coursesProvider: CoreCoursesProvider) { }

View File

@ -25,6 +25,12 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
* Interface that all course format handlers must implement. * Interface that all course format handlers must implement.
*/ */
export interface CoreCourseFormatHandler extends CoreDelegateHandler { export interface CoreCourseFormatHandler extends CoreDelegateHandler {
/**
* Name of the format the handler supports. E.g. 'singleactivity'.
* @type {string}
*/
format: string;
/** /**
* Get the title to use in course page. If not defined, course fullname. * Get the title to use in course page. If not defined, course fullname.
* This function will be called without sections first, and then call it again when the sections are retrieved. * This function will be called without sections first, and then call it again when the sections are retrieved.
@ -151,7 +157,8 @@ export interface CoreCourseFormatHandler extends CoreDelegateHandler {
export class CoreCourseFormatDelegate extends CoreDelegate { export class CoreCourseFormatDelegate extends CoreDelegate {
protected handlers: { [s: string]: CoreCourseFormatHandler } = {}; // All registered handlers. protected handlers: { [s: string]: CoreCourseFormatHandler } = {}; // All registered handlers.
protected enabledHandlers: { [s: string]: CoreCourseFormatHandler } = {}; // Handlers enabled for the current site. protected enabledHandlers: { [s: string]: CoreCourseFormatHandler } = {}; // Handlers enabled for the current site.
protected featurePrefix = 'CoreCourseFormatHandler_'; protected featurePrefix = 'CoreCourseFormatDelegate_';
protected handlerNameProperty = 'format';
constructor(loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, constructor(loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider,
protected defaultHandler: CoreCourseFormatDefaultHandler) { protected defaultHandler: CoreCourseFormatDefaultHandler) {

View File

@ -25,6 +25,12 @@ import { CoreDelegate, CoreDelegateHandler } from '@classes/delegate';
* Interface that all course module handlers must implement. * Interface that all course module handlers must implement.
*/ */
export interface CoreCourseModuleHandler extends CoreDelegateHandler { export interface CoreCourseModuleHandler extends CoreDelegateHandler {
/**
* Name of the module. It should match the "modname" of the module returned in core_course_get_contents.
* @type {string}
*/
modName: string;
/** /**
* Get the data required to display the module in the course contents view. * Get the data required to display the module in the course contents view.
* *
@ -169,6 +175,7 @@ export class CoreCourseModuleDelegate extends CoreDelegate {
protected handlers: { [s: string]: CoreCourseModuleHandler } = {}; // All registered handlers. protected handlers: { [s: string]: CoreCourseModuleHandler } = {}; // All registered handlers.
protected enabledHandlers: { [s: string]: CoreCourseModuleHandler } = {}; // Handlers enabled for the current site. protected enabledHandlers: { [s: string]: CoreCourseModuleHandler } = {}; // Handlers enabled for the current site.
protected featurePrefix = 'CoreCourseModuleDelegate_'; protected featurePrefix = 'CoreCourseModuleDelegate_';
protected handlerNameProperty = 'modName';
constructor(loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider, constructor(loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, eventsProvider: CoreEventsProvider,
protected courseProvider: CoreCourseProvider) { protected courseProvider: CoreCourseProvider) {

View File

@ -56,6 +56,12 @@ export type CoreCourseModulesProgressFunction = (data: CoreCourseModulesProgress
* Interface that all course prefetch handlers must implement. * Interface that all course prefetch handlers must implement.
*/ */
export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler { export interface CoreCourseModulePrefetchHandler extends CoreDelegateHandler {
/**
* Name of the module. It should match the "modname" of the module returned in core_course_get_contents.
* @type {string}
*/
modName: string;
/** /**
* The handler's component. * The handler's component.
* @type {string} * @type {string}
@ -214,6 +220,7 @@ export class CoreCourseModulePrefetchDelegate extends CoreDelegate {
protected ROOT_CACHE_KEY = 'mmCourse:'; protected ROOT_CACHE_KEY = 'mmCourse:';
protected statusCache = new CoreCache(); protected statusCache = new CoreCache();
protected handlerNameProperty = 'modName';
// Promises for check updates, to prevent performing the same request twice at the same time. // Promises for check updates, to prevent performing the same request twice at the same time.
protected courseUpdatesPromises: { [s: string]: { [s: string]: Promise<any> } } = {}; protected courseUpdatesPromises: { [s: string]: { [s: string]: Promise<any> } } = {};

View File

@ -22,7 +22,7 @@ import { CoreSitePluginsCourseFormatComponent } from '../components/course-forma
*/ */
export class CoreSitePluginsCourseFormatHandler extends CoreSitePluginsBaseHandler implements CoreCourseFormatHandler { export class CoreSitePluginsCourseFormatHandler extends CoreSitePluginsBaseHandler implements CoreCourseFormatHandler {
constructor(name: string, protected handlerSchema: any) { constructor(name: string, public format: string, protected handlerSchema: any) {
super(name); super(name);
} }

View File

@ -24,7 +24,7 @@ import { CoreSitePluginsModuleIndexComponent } from '../components/module-index/
export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler implements CoreCourseModuleHandler { export class CoreSitePluginsModuleHandler extends CoreSitePluginsBaseHandler implements CoreCourseModuleHandler {
priority: number; priority: number;
constructor(name: string, protected handlerSchema: any) { constructor(name: string, public modName: string, protected handlerSchema: any) {
super(name); super(name);
} }

View File

@ -22,12 +22,13 @@ import { CoreCourseModulePrefetchHandlerBase } from '@core/course/classes/module
export class CoreSitePluginsModulePrefetchHandler extends CoreCourseModulePrefetchHandlerBase { export class CoreSitePluginsModulePrefetchHandler extends CoreCourseModulePrefetchHandlerBase {
protected ROOT_CACHE_KEY = 'CoreSitePluginsModulePrefetchHandler:'; protected ROOT_CACHE_KEY = 'CoreSitePluginsModulePrefetchHandler:';
constructor(injector: Injector, protected sitePluginsProvider: CoreSitePluginsProvider, component: string, modName: string, constructor(injector: Injector, protected sitePluginsProvider: CoreSitePluginsProvider, component: string, name: string,
protected handlerSchema: any) { modName: string, protected handlerSchema: any) {
super(injector); super(injector);
this.component = component; this.component = component;
this.name = modName; this.name = name;
this.modName = modName;
this.isResource = handlerSchema.isresource; this.isResource = handlerSchema.isresource;
if (handlerSchema.updatesnames) { if (handlerSchema.updatesnames) {

View File

@ -22,7 +22,7 @@ import { CoreSitePluginsUserProfileFieldComponent } from '../components/user-pro
*/ */
export class CoreSitePluginsUserProfileFieldHandler extends CoreSitePluginsBaseHandler implements CoreUserProfileFieldHandler { export class CoreSitePluginsUserProfileFieldHandler extends CoreSitePluginsBaseHandler implements CoreUserProfileFieldHandler {
constructor(name: string) { constructor(name: string, public type: string) {
super(name); super(name);
} }

View File

@ -353,8 +353,9 @@ export class CoreSitePluginsHelperProvider {
this.logger.debug('Register site plugin in course format delegate:', plugin, handlerSchema, bootstrapResult); this.logger.debug('Register site plugin in course format delegate:', plugin, handlerSchema, bootstrapResult);
// Create and register the handler. // Create and register the handler.
const formatName = plugin.component.replace('format_', ''); const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
this.courseFormatDelegate.registerHandler(new CoreSitePluginsCourseFormatHandler(formatName, handlerSchema)); formatName = plugin.component.replace('format_', '');
this.courseFormatDelegate.registerHandler(new CoreSitePluginsCourseFormatHandler(uniqueName, formatName, handlerSchema));
return formatName; return formatName;
} }
@ -437,14 +438,15 @@ export class CoreSitePluginsHelperProvider {
this.logger.debug('Register site plugin in module delegate:', plugin, handlerSchema, bootstrapResult); this.logger.debug('Register site plugin in module delegate:', plugin, handlerSchema, bootstrapResult);
// Create and register the handler. // Create and register the handler.
const modName = plugin.component.replace('mod_', ''); const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
modName = plugin.component.replace('mod_', '');
this.moduleDelegate.registerHandler(new CoreSitePluginsModuleHandler(modName, handlerSchema)); this.moduleDelegate.registerHandler(new CoreSitePluginsModuleHandler(uniqueName, modName, handlerSchema));
if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) { if (handlerSchema.offlinefunctions && Object.keys(handlerSchema.offlinefunctions).length) {
// Register the prefetch handler. // Register the prefetch handler.
this.prefetchDelegate.registerHandler(new CoreSitePluginsModulePrefetchHandler( this.prefetchDelegate.registerHandler(new CoreSitePluginsModulePrefetchHandler(
this.injector, this.sitePluginsProvider, plugin.component, modName, handlerSchema)); this.injector, this.sitePluginsProvider, plugin.component, uniqueName, modName, handlerSchema));
} }
return modName; return modName;
@ -502,8 +504,9 @@ export class CoreSitePluginsHelperProvider {
// Execute the main method and its JS. The template returned will be used in the profile field component. // Execute the main method and its JS. The template returned will be used in the profile field component.
return this.executeMethodAndJS(plugin, handlerSchema.method).then((result) => { return this.executeMethodAndJS(plugin, handlerSchema.method).then((result) => {
// Create and register the handler. // Create and register the handler.
const fieldType = plugin.component.replace('profilefield_', ''), const uniqueName = this.sitePluginsProvider.getHandlerUniqueName(plugin, handlerName),
fieldHandler = new CoreSitePluginsUserProfileFieldHandler(fieldType); fieldType = plugin.component.replace('profilefield_', ''),
fieldHandler = new CoreSitePluginsUserProfileFieldHandler(uniqueName, fieldType);
// Store in handlerSchema some data required by the component. // Store in handlerSchema some data required by the component.
handlerSchema.methodTemplates = result.templates; handlerSchema.methodTemplates = result.templates;

View File

@ -19,6 +19,11 @@ import { CoreSitesProvider } from '@providers/sites';
import { CoreEventsProvider } from '@providers/events'; import { CoreEventsProvider } from '@providers/events';
export interface CoreUserProfileFieldHandler extends CoreDelegateHandler { export interface CoreUserProfileFieldHandler extends CoreDelegateHandler {
/**
* Type of the field the handler supports. E.g. 'checkbox'.
* @type {string}
*/
type: string;
/** /**
* Return the Component to use to display the user profile field. * Return the Component to use to display the user profile field.
@ -68,6 +73,7 @@ export interface CoreUserProfileFieldHandlerData {
export class CoreUserProfileFieldDelegate extends CoreDelegate { export class CoreUserProfileFieldDelegate extends CoreDelegate {
protected handlers: { [s: string]: CoreUserProfileFieldHandler } = {}; protected handlers: { [s: string]: CoreUserProfileFieldHandler } = {};
protected enabledHandlers: { [s: string]: CoreUserProfileFieldHandler } = {}; protected enabledHandlers: { [s: string]: CoreUserProfileFieldHandler } = {};
protected handlerNameProperty = 'type';
constructor(protected loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider, constructor(protected loggerProvider: CoreLoggerProvider, protected sitesProvider: CoreSitesProvider,
protected eventsProvider: CoreEventsProvider) { protected eventsProvider: CoreEventsProvider) {