MDL-78597 mod_lti: add cartridge support to course tool generator

Allow the generator to create course tools based on cartridge URLs.
This commit is contained in:
Jake Dallimore 2023-08-09 16:12:21 +08:00
parent 93707d8cf5
commit dfd215cad2
No known key found for this signature in database

View File

@ -98,7 +98,7 @@ class mod_lti_generator extends testing_module_generator {
* - 'ltiservice_' prefix: denotes 'config' data, specifically config for service plugins.
*
* @param array $data array of type and config data containing prefixed keys.
* @return array containing separated type and config data. E.g. ['type' = [...], 'config' => [...]]
* @return array containing separated objects for type and config data. E.g. ['type' = stdClass, 'config' => stdClass]
*/
protected function get_type_and_config_from_data(array $data): array {
// Grab any non-prefixed fields; these are the type fields. The rest is considered config.
@ -109,7 +109,7 @@ class mod_lti_generator extends testing_module_generator {
);
$config = array_diff_key($data, $type);
return ['type' => $type, 'config' => $config];
return ['type' => (object) $type, 'config' => (object) $config];
}
/**
@ -159,8 +159,18 @@ class mod_lti_generator extends testing_module_generator {
$type['lti_sendname'] = $type['lti_sendname'] ?? LTI_SETTING_ALWAYS;
$type['lti_sendemailaddr'] = $type['lti_sendemailaddr'] ?? LTI_SETTING_ALWAYS;
// Required for cartridge processing support.
$type['lti_toolurl'] = $type['baseurl'];
$type['lti_description'] = $type['description'] ?? '';
$type['lti_icon'] = $type['icon'] ?? '';
$type['lti_secureicon'] = $type['secureicon'] ?? '';
if (!empty($type['name'])) {
$type['lti_typename'] = $type['name'];
}
['type' => $type, 'config' => $config] = $this->get_type_and_config_from_data($type);
lti_add_type(type: (object) $type, config: (object) $config);
lti_load_type_if_cartridge($config);
lti_add_type(type: $type, config: $config);
}
}