mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-66609: core_h5p: Add <component>_get_path_from_pluginfile method
This method has been added to all the components having some exceptions with the way they treat the itemid in the pluginfile paths.
This commit is contained in:
parent
9e67f5e366
commit
810d7a3d2e
8 changed files with 177 additions and 0 deletions
|
@ -584,3 +584,28 @@ function mod_resource_core_calendar_provide_event_action(calendar_event $event,
|
|||
true
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given an array with a file path, it returns the itemid and the filepath for the defined filearea.
|
||||
*
|
||||
* @param string $filearea The filearea.
|
||||
* @param array $args The path (the part after the filearea and before the filename).
|
||||
* @return array The itemid and the filepath inside the $args path, for the defined filearea.
|
||||
*/
|
||||
function mod_resource_get_path_from_pluginfile(string $filearea, array $args) : array {
|
||||
// Resource never has an itemid (the number represents the revision but it's not stored in database).
|
||||
array_shift($args);
|
||||
|
||||
// Get the filepath.
|
||||
if (empty($args)) {
|
||||
$filepath = '/';
|
||||
} else {
|
||||
$filepath = '/' . implode('/', $args) . '/';
|
||||
}
|
||||
|
||||
return [
|
||||
'itemid' => 0,
|
||||
'filepath' => $filepath,
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue