General developer forum

LTI Source sub-plugin as activity

 
Picture of Martin Rieva
LTI Source sub-plugin as activity
 

Although new to both Moodle and PHP I have done an LTI Source sub-plugin with some moderate success. The sub-plugin registers as an activity using the get_shortcuts() hook and adds itself with a different type:

function ltisource_ecohub_get_shortcuts($defaultitem) {
global $OUTPUT;

$grouptitle = get_string('modulenameplural', 'mod_lti');
$type = 'ecohub';
$name = get_string('pluginname', 'ltisource_ecohub');

$item = new stdClass();
$item->title = get_string('activitytypetitle', '', (object)['activity' => $grouptitle, 'type' => $name]);
$item->type = 'lti&type=' . $type;
$item->name = $name;
$item->link = new moodle_url($defaultitem->link, array('type' => $type));
$item->help = get_string('pluginhelp', 'ltisource_ecohub');
// TODO: This simply doesn't work for some reason. Investigation ongoing.
$item->icon = $OUTPUT->image_icon('icon', '', 'ltisource_ecohub', array('class' => 'icon'));

$items = array($item);
return $items;
}
The idea is to add extra information to the LTI launch when using this activity, which is done in the before_launch() hook.

My problem is that I just want to modify the LTI launch when this activity is used and not when the parent/general LTI activity is used. In the before_launch() hook I cannot detect if the launch is initiated by my sub-plugin or the External Tools LTI activity, which I hoped could be done by checking the type provided in the code above.

Is there another way to detect this?

I am using Moodle 3.3 and the full sub-plugin code can be found here: https://bitbucket.org/laerdalmedical/moodle-ltisource-ecohub/src

Bonus question:
The observant reader will note the TODO in the above code. The icon is shown correctly during plugin update, but in the Activities form it is replaced with the LTI icon. Howcome?

Any help is much appreciated!

 
Average of ratings: -
Picture of Martin Rieva
Ang: LTI Source sub-plugin as activity
 

Should this have been posted in LTI and Moodle https://moodle.org/mod/forum/view.php?id=7978 or developer forum https://moodle.org/mod/forum/view.php?id=55?

I have no clue how to move this.

 
Average of ratings: -
Picture of Helen Foster
Re: LTI Source sub-plugin as activity
Core developersDocumentation writersMoodle HQParticularly helpful MoodlersPlugin developersTestersTranslators

Hi Martin,

Sorry I can't answer your question, however I have moved your post to the LTI and Moodle forum where you'll hopefully receive help.

 
Average of ratings: -
Picture of Martin Rieva
Ang: Re: LTI Source sub-plugin as activity
 

Thanks Helen smile

 
Average of ratings: -
Picture of Helen Foster
Re: LTI Source sub-plugin as activity
Core developersDocumentation writersMoodle HQParticularly helpful MoodlersPlugin developersTestersTranslators

Hmm, as nobody else has replied, I'm going to try moving your post to the General dev forum...

 
Average of ratings: -
Picture of Darko Miletić
Re: LTI Source sub-plugin as activity
Core developersParticularly helpful Moodlers

You should be able to detect they type of launch in the hook. The hook receives $instance object which is a record from prefix_lti table.

In there there is a toolurl and typeid field. typeid is id of the tool from prefix_lti_types table.

During registration of your subplugin tool data you should store somewhere info saying "this typeid is mine" than in the hook just do the check.

 
Average of ratings: -
Picture of Martin Rieva
Ang: Re: LTI Source sub-plugin as activity
 

Hi Darko,

Thanks for your reply. It seems that the prefix_lti_types (and prefix_lti_types_config) is used for pre-configured external tools or external tool registrations using LTI 2.0.

If my sub-plugin creates a new type id in the prefix_lti_types table, I expect it to appear in the Manage tools settings page, which is not the intended behavior. It kinda seems like a misuse of the external tools implementation.

Maybe the real problem here is that courses configured with LTI sub-plugins (LTI Source) cannot be distinguished from courses created using the standard LTI activity?

 
Average of ratings: -
Picture of Darko Miletić
Re: Ang: Re: LTI Source sub-plugin as activity
Core developersParticularly helpful Moodlers

The only thing that distinguishes one LTI tool from another is the actual URL. The LTI subplugins are designed as kind of global hooks. By default they apply to any LTI activity. It is responsibility of the subplugin developer to provide filtering if needed and the only way to do that is to "know" that tool X is my tool, the tool that I should hook into. So the system of subplugins is shaky but it was added a posteriori with idea of not breaking anything in the original LTI functionality. You just have to work within those limits.


 
Average of ratings: -
Picture of Martin Rieva
Ang: Re: Ang: Re: LTI Source sub-plugin as activity
 

Okay, that makes sense then.

I am currently filtering on URL anyway, so changing the implementation would be jumping hoops to accomplish, in essence, the same thing.

Thanks for the clarification!

 
Average of ratings: -
Picture of Luis de la Torre
Re: Ang: Re: Ang: Re: LTI Source sub-plugin as activity
Plugin developers

Hi Martin,


I found the same problem and reported it in the tracker some months ago: https://tracker.moodle.org/browse/MDL-60223


Marina Glancy offered a good solution for my problem. Check it out and participate in the discussion if you want.


Cheers.

 
Average of ratings: -
Picture of Martin Rieva
Ang: Re: Ang: Re: Ang: Re: LTI Source sub-plugin as activity
 

Hi Luis,

Thanks for posting here. I did notice your issue some time ago. That is why I actually get two activities in the chooser, but the Marina's workaround does not allow for the extra parameter being passed to the $instance, which is passed in the before_launch. That is, in essence, my real problem.

But I also noticed the icon for my sub-plugin being the same as the standard LTI icon, not the one I supplied in the get_shortcuts.

 
Average of ratings: -
Picture of Luis de la Torre
Re: Ang: Re: Ang: Re: Ang: Re: LTI Source sub-plugin as activity
Plugin developers

I think you should add that comment to the issue discussion in the tracker so they keep record of that and have it in mind for possible future fixes in Moodle!

 
Average of ratings: -