mirror of
https://github.com/moodle/moodle.git
synced 2025-08-02 15:49:43 +02:00
MDL-68011 core: Final deprecation of get_module_metadata()
This commit is contained in:
parent
d9632ca8b2
commit
2ca262a5e3
2 changed files with 5 additions and 95 deletions
|
@ -2770,102 +2770,11 @@ function report_insights_context_insights(\context $context) {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieve all metadata for the requested modules
|
||||
*
|
||||
* @deprecated since 3.9.
|
||||
* @param object $course The Course
|
||||
* @param array $modnames An array containing the list of modules and their
|
||||
* names
|
||||
* @param int $sectionreturn The section to return to
|
||||
* @return array A list of stdClass objects containing metadata about each
|
||||
* module
|
||||
* @deprecated since 3.9
|
||||
*/
|
||||
function get_module_metadata($course, $modnames, $sectionreturn = null) {
|
||||
global $OUTPUT;
|
||||
|
||||
debugging('get_module_metadata is deprecated. Please use \core_course\local\service\content_item_service instead.');
|
||||
|
||||
// get_module_metadata will be called once per section on the page and courses may show
|
||||
// different modules to one another
|
||||
static $modlist = array();
|
||||
if (!isset($modlist[$course->id])) {
|
||||
$modlist[$course->id] = array();
|
||||
}
|
||||
|
||||
$return = array();
|
||||
$urlbase = new moodle_url('/course/mod.php', array('id' => $course->id, 'sesskey' => sesskey()));
|
||||
if ($sectionreturn !== null) {
|
||||
$urlbase->param('sr', $sectionreturn);
|
||||
}
|
||||
foreach($modnames as $modname => $modnamestr) {
|
||||
if (!course_allowed_module($course, $modname)) {
|
||||
continue;
|
||||
}
|
||||
if (isset($modlist[$course->id][$modname])) {
|
||||
// This module is already cached
|
||||
$return += $modlist[$course->id][$modname];
|
||||
continue;
|
||||
}
|
||||
$modlist[$course->id][$modname] = array();
|
||||
|
||||
// Create an object for a default representation of this module type in the activity chooser. It will be used
|
||||
// if module does not implement callback get_shortcuts() and it will also be passed to the callback if it exists.
|
||||
$defaultmodule = new stdClass();
|
||||
$defaultmodule->title = $modnamestr;
|
||||
$defaultmodule->name = $modname;
|
||||
$defaultmodule->link = new moodle_url($urlbase, array('add' => $modname));
|
||||
$defaultmodule->icon = $OUTPUT->pix_icon('icon', '', $defaultmodule->name, array('class' => 'icon'));
|
||||
$sm = get_string_manager();
|
||||
if ($sm->string_exists('modulename_help', $modname)) {
|
||||
$defaultmodule->help = get_string('modulename_help', $modname);
|
||||
if ($sm->string_exists('modulename_link', $modname)) { // Link to further info in Moodle docs.
|
||||
$link = get_string('modulename_link', $modname);
|
||||
$linktext = get_string('morehelp');
|
||||
$defaultmodule->help .= html_writer::tag('div',
|
||||
$OUTPUT->doc_link($link, $linktext, true), array('class' => 'helpdoclink'));
|
||||
}
|
||||
}
|
||||
$defaultmodule->archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
|
||||
|
||||
// Each module can implement callback modulename_get_shortcuts() in its lib.php and return the list
|
||||
// of elements to be added to activity chooser.
|
||||
$items = component_callback($modname, 'get_shortcuts', array($defaultmodule), null);
|
||||
if ($items !== null) {
|
||||
foreach ($items as $item) {
|
||||
// Add all items to the return array. All items must have different links, use them as a key in the return array.
|
||||
if (!isset($item->archetype)) {
|
||||
$item->archetype = $defaultmodule->archetype;
|
||||
}
|
||||
if (!isset($item->icon)) {
|
||||
$item->icon = $defaultmodule->icon;
|
||||
}
|
||||
// If plugin returned the only one item with the same link as default item - cache it as $modname,
|
||||
// otherwise append the link url to the module name.
|
||||
$item->name = (count($items) == 1 &&
|
||||
$item->link->out() === $defaultmodule->link->out()) ? $modname : $modname . ':' . $item->link;
|
||||
|
||||
// If the module provides the helptext property, append it to the help text to match the look and feel
|
||||
// of the default course modules.
|
||||
if (isset($item->help) && isset($item->helplink)) {
|
||||
$linktext = get_string('morehelp');
|
||||
$item->help .= html_writer::tag('div',
|
||||
$OUTPUT->doc_link($item->helplink, $linktext, true), array('class' => 'helpdoclink'));
|
||||
}
|
||||
$modlist[$course->id][$modname][$item->name] = $item;
|
||||
}
|
||||
$return += $modlist[$course->id][$modname];
|
||||
// If get_shortcuts() callback is defined, the default module action is not added.
|
||||
// It is a responsibility of the callback to add it to the return value unless it is not needed.
|
||||
continue;
|
||||
}
|
||||
|
||||
// The callback get_shortcuts() was not found, use the default item for the activity chooser.
|
||||
$modlist[$course->id][$modname][$modname] = $defaultmodule;
|
||||
$return[$modname] = $defaultmodule;
|
||||
}
|
||||
|
||||
core_collator::asort_objects_by_property($return, 'title');
|
||||
return $return;
|
||||
function get_module_metadata() {
|
||||
throw new coding_exception(
|
||||
'get_module_metadata() has been removed. Please use \core_course\local\service\content_item_service instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,6 +37,7 @@ information provided here is intended especially for developers.
|
|||
* Added $CFG->proxylogunsafe and proxyfixunsafe to detect code which doesn't honor the proxy config
|
||||
* Function admin_externalpage_setup() now has additional option 'nosearch' allowing to remove Site administration search form.
|
||||
* The function print_error has been deprecated. Kindly use moodle_exception.
|
||||
* The function get_module_metadata() has been finally deprecated and can not be used anymore.
|
||||
|
||||
=== 4.0 ===
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue