diff --git a/classes/file_storage.php b/classes/file_storage.php
index 260ea674da3b823dc65ebea0dcb417a7f9fa0daf..ea9fd52ffc15a0f4acdaea42e09f3ab2c64e9322 100644
--- a/classes/file_storage.php
+++ b/classes/file_storage.php
@@ -378,9 +378,9 @@ class file_storage implements \H5PFileStorage {
*
* @param string $file path + name
* @param string|int $fromid Content ID or 'editor' string
- * @param int $toid Target Content ID
+ * @param stdClass $tocontent Target Content
*/
- public function cloneContentFile($file, $fromid, $toid) {
+ public function cloneContentFile($file, $fromid, $tocontent) {
// Determine source file area and item id
$sourcefilearea = ($fromid === 'editor' ? $fromid : 'content');
$sourceitemid = ($fromid === 'editor' ? 0 : $fromid);
@@ -392,20 +392,19 @@ class file_storage implements \H5PFileStorage {
}
// Check to make sure source doesn't exist already
- if ($this->getFile('content', $toid, $file) !== false) {
+ if ($this->getFile('content', $tocontent, $file) !== false) {
return; // File exists, no need to copy
}
- // Grab context for cm
- $cm = \get_coursemodule_from_instance('hvp', $toid);
- $context = \context_module::instance($cm->id);
+ // Grab context for CM
+ $context = \context_module::instance($tocontent->coursemodule);
// Create new file record
$record = array(
'contextid' => $context->id,
'component' => 'mod_hvp',
'filearea' => 'content',
- 'itemid' => $toid,
+ 'itemid' => $tocontent->id,
'filepath' => $this->getFilepath($file),
'filename' => $this->getFilename($file)
);
@@ -418,11 +417,11 @@ class file_storage implements \H5PFileStorage {
* Used when saving content.
*
* @param string $file path + name
- * @param int $contentid
+ * @param stdClass $content
* @return string|int File ID or NULL if not found
*/
- public function getContentFile($file, $contentid) {
- $file = $this->getFile('content', $contentid, $file);
+ public function getContentFile($file, $content) {
+ $file = $this->getFile('content', $content, $file);
return ($file === false ? null : $file->get_id());
}
@@ -431,10 +430,10 @@ class file_storage implements \H5PFileStorage {
* Used when saving content.
*
* @param string $file path + name
- * @param int $contentid
+ * @param stdClass $content
*/
- public function removeContentFile($file, $contentid) {
- $file = $this->getFile('content', $contentid, $file);
+ public function removeContentFile($file, $content) {
+ $file = $this->getFile('content', $content, $file);
if ($file !== false) {
$file->delete();
}
@@ -547,7 +546,7 @@ class file_storage implements \H5PFileStorage {
* Help make it easy to load content files.
*
* @param string $filearea
- * @param int $itemid
+ * @param int|stdClass $itemid
* @param string $file path + name
*/
private function getFile($filearea, $itemid, $file) {
@@ -557,8 +556,13 @@ class file_storage implements \H5PFileStorage {
// Use Course context
$context = \context_course::instance($COURSE->id);
}
+ elseif (is_object($itemid)) {
+ // Grab CM context from item
+ $context = \context_module::instance($itemid->coursemodule);
+ $itemid = $itemid->id;
+ }
else {
- // Use CM context
+ // Use item ID to find CM context
$cm = \get_coursemodule_from_instance('hvp', $itemid);
$context = \context_module::instance($cm->id);
}
diff --git a/editor b/editor
index 23f20f7bafd8e8c9ddafe5a6768c42f01975b0e7..d1ad5947b82ccbe2c3badad8d804f4d44fdc8efa 160000
--- a/editor
+++ b/editor
@@ -1 +1 @@
-Subproject commit 23f20f7bafd8e8c9ddafe5a6768c42f01975b0e7
+Subproject commit d1ad5947b82ccbe2c3badad8d804f4d44fdc8efa
diff --git a/lib.php b/lib.php
index caf5b294b063d0c708915ed1a748cfd9ab7987b7..d8154ff6028b1558076aa1ea755eee9ae1ffc774 100644
--- a/lib.php
+++ b/lib.php
@@ -159,7 +159,7 @@ function hvp_save_content($hvp) {
$params = json_decode($hvp->params);
// Move any uploaded images or files. Determine content dependencies.
- $editor->processParameters($hvp->id, $hvp->library, $params, isset($oldlib) ? $oldlib : NULL, isset($oldparams) ? $oldparams : NULL);
+ $editor->processParameters($hvp, $hvp->library, $params, isset($oldlib) ? $oldlib : NULL, isset($oldparams) ? $oldparams : NULL);
}
return $hvp->id;