Moodle for mobile

What is registerLinkHandler for?

 
Picture of Mike Churchward
What is registerLinkHandler for?
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developersGroup Plugins guardiansGroup Testers

Hi -

While working on a new plugin for mobile, I can see that the examples (certificate, in particular) register a link handler along with a content handler, using a statement like:

$mmContentLinksDelegateProvider.registerLinkHandler('mmaModCertificate', '$mmaModCertificateHandlers.linksHandler');

What is this handler for? Where is it actually used?

mike

 
Average of ratings: -
Picture of Neill Magill
Re: What is registerLinkHandler for?
Group Core developersGroup Plugin developers

I believe it parses links and determines if they should be redirected to a page in the Mobile app.

i.e. if someone linked to http://yoursite.com/mod/youractivity/view.php in some text on yoursite.com and was accessing it in the Mobile app then the youractivity link handler would redirect it to the main view page in the app for youractivity

 
Average of ratings: -
Picture of Mike Churchward
Re: What is registerLinkHandler for?
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developersGroup Plugins guardiansGroup Testers

Ah. Interesting. Thank you.

I'll test that out.

mike

 
Average of ratings: -
Picture of Mike Churchward
Re: What is registerLinkHandler for?
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developersGroup Plugins guardiansGroup Testers

Looking at two examples of modules that use the "registerLinkHandler", I see two very different ways of implementing it:

For the certificate, the main.js uses

$mmContentLinksDelegateProvider.registerLinkHandler('mmaModCertificate', '$mmaModCertificateHandlers.linksHandler');

While the feedback module's main.js uses:

$mmContentLinksDelegateProvider.registerLinkHandler('mmaModFeedback:index', '$mmaModFeedbackHandlers.indexLinksHandler');

Note that the feedback version has an ":index" in the definition statement.

Then in the handlers.js, the certificate has a series of functions defined to handle the links, while the feedback has only one line of code:

self.indexLinksHandler = $mmContentLinksHelper.createModuleIndexLinkHandler('mmaModFeedback', 'feedback', $mmaModFeedback);

Is the feedback  version a "shortcut" that can be used instead of all of the code used in the certificate module?

mike

 
Average of ratings: -
Picture of Neill Magill
Re: What is registerLinkHandler for?
Group Core developersGroup Plugin developers

Dani Palou pointed to the current way of implementing them at: https://github.com/moodlehq/moodlemobile2/blob/master/www/addons/mod/forum/services/handlers.js#L161

It made implementing a handler for the view.php very simple.

 
Average of ratings: -
Picture of Mike Churchward
Re: What is registerLinkHandler for?
Group Core developersGroup Particularly helpful MoodlersGroup Plugin developersGroup Plugins guardiansGroup Testers

So, the one line used in feedback is newer than the certificate implementation? Any idea what the ":index" part is for in main.js?

mike

 
Average of ratings: -
Picture of Neill Magill
Re: What is registerLinkHandler for?
Group Core developersGroup Plugin developers

Seems to be the newer implementation yes.

My guess is that the ":index" is part of a convention to ensure that plugins using multiple link handlers for plugin have a unique name.

 
Average of ratings: -
Picture of Dani Palou
Re: What is registerLinkHandler for?
Group Core developersGroup Moodle HQGroup Particularly helpful MoodlersGroup Plugin developers

Hello Mike,

as Neill explained, we changed the way to implement these links handlers to make it easier for developers. You should implement it like it's done in feedback.

Neill is right about the ":index" too, it's to make sure the name is unique. This name is only used to identify the handler, it isn't used for anything else. With the old implementation of links handler, the modules had a single handler to treat all the possible links of your module. With the new implementation, the addons will have a link handler for each type of link, that's why we add those prefixes to make each name unique.

Kind regards,

Dani

 
Average of ratings: -