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:
Sara Arjona 2019-10-17 22:20:13 +02:00 committed by Andrew Nicols
parent 9e67f5e366
commit 810d7a3d2e
8 changed files with 177 additions and 0 deletions

View file

@ -109,3 +109,27 @@ function block_html_global_db_replace($search, $replace) {
}
$instances->close();
}
/**
* 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 block_html_get_path_from_pluginfile(string $filearea, array $args) : array {
// This block 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,
];
}