Plugin mobile support: link to a core mod view

Plugin mobile support: link to a core mod view

by Teja C -
Number of replies: 4

Hello,

I am adding mobile support for a custom-developed plugin.

In the main view (called from method mobile_course_view) I have a list of records and would like to add a link to attempt review to each of them.
I tried using the core-site-plugins-new-content directive like this:

<button ion-button block color="light" core-site-plugins-new-content title="Klikni" component="mod_quiz" method="get_attempt_review">Click here</button>

But when I click on the button, I get the following error: Missing method in \mod_quiz\output\mobile

How I can create a link/load content from core modules? I believe I will have to include some additional arguments with [args], but for now I would like to successfully call the correspondent view/service.

I would appreciate any help or pointers.


Average of ratings: -
In reply to Teja C

Re: Plugin mobile support: link to a core mod view

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Hi Teja, The reason you're having problems is that the core components of the app aren't implemented as site plugins, as our custom plugins are. They are implemented directly within the app, as Angular modules (these are called "addons" in the app's code).

What you've told the app to do is load a new page by calling the \mod_quiz\output\mobile::get_attempt_review(), but if you look in mod_quiz, you'll see it has no mobile class in classes/output.

One possibility would be to replace core-site-plugins-new-content with core-site-plugins-call-ws-new-content, if you can make that do what you want.

Another possibility is to have a javascript function to load the page from the mod_quiz addon, something like:

(function(t) {
    function openQuizAttempt(event) {
        t.NavController.push('addon-mod-quiz-attempt', [attemptId, quizId, courseId]);
    }
})(this);

Then attach it to your button with (click)="openQuizAttempt($event)"

If you've not got your head around Javascript in your plugins yet, check out this thread where we discussed it recently.

In reply to Mark Johnson

Odg: Re: Plugin mobile support: link to a core mod view

by Teja C -
Hi Mark,
thank you for your prompt reply. I suspected as much regarding the difference between core modules and plugins.

I have now tried with core-site-plugins-call-ws-new-content and I get the data I expected, but also an error which I think is coming from JS (Cannot convert undefined or null to object.)
Since I only get data as JSON, I suppose I have to do something with it, i.e. provide the page/template that is going to be shown? I cannot find this information in the documentation.

I have not yet tried the JS approach, but if I understand correctly, I can load this specific page (attempt review) with it - like I would, for example, create an <a> link in HTML?
In reply to Teja C

Re: Odg: Re: Plugin mobile support: link to a core mod view

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Yes, you can add the (click) attribute to a link or button in your template.

Slight adjustment to what I posted above, I think the page ID is "AddonModQuizAttemptPage", so you'd do push('AddonModQuizAttemptPage', ...).

In reply to Mark Johnson

Odg: Re: Odg: Re: Plugin mobile support: link to a core mod view

by Teja C -
Thank you.
I have achieved what I needed using t.NavController.push('AddonModQuizReviewPage', {"attemptId": attemptId, "quizId": quizId, "courseId": courseId});.