From 3149defec15dd11775a7139c86416ead31b1ac43 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Tue, 26 May 2020 15:11:27 +0200 Subject: [PATCH 1/3] MDL-68578 contenttype_h5p: Save content title from uploaded H5P file --- h5p/classes/framework.php | 11 ++++++++++- h5p/classes/helper.php | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/h5p/classes/framework.php b/h5p/classes/framework.php index 4524f0af059..2e4a2cad269 100644 --- a/h5p/classes/framework.php +++ b/h5p/classes/framework.php @@ -796,7 +796,12 @@ class framework implements \H5PFrameworkInterface { } $content['disable'] = $content['disable'] ?? null; - + // Add title to 'params' to use in the editor. + if (!empty($content['title'])) { + $params = json_decode($content['params']); + $params->title = $content['title']; + $content['params'] = json_encode($params); + } $data = [ 'jsoncontent' => $content['params'], 'displayoptions' => $content['disable'], @@ -1206,6 +1211,10 @@ class framework implements \H5PFrameworkInterface { if (empty($params->metadata)) { $params->metadata = new \stdClass(); } + // Add title to metadata. + if (!empty($params->title) && empty($params->metadata->title)) { + $params->metadata->title = $params->title; + } $content['metadata'] = $params->metadata; $content['params'] = json_encode($params->params ?? $params); diff --git a/h5p/classes/helper.php b/h5p/classes/helper.php index 8e85ffc99eb..721187e3feb 100644 --- a/h5p/classes/helper.php +++ b/h5p/classes/helper.php @@ -75,6 +75,10 @@ class helper { ]; $options = ['disable' => self::get_display_options($core, $config)]; + // Add the 'title' if exists from 'h5p.json' data to keep it for the editor. + if (!empty($h5pvalidator->h5pC->mainJsonData['title'])) { + $content['title'] = $h5pvalidator->h5pC->mainJsonData['title']; + } $h5pstorage->savePackage($content, null, $skipcontent, $options); return $h5pstorage->contentId; From 6219740b8eb22a532c1fa791325f5cb4b4eb20ca Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Tue, 26 May 2020 17:34:28 +0200 Subject: [PATCH 2/3] MDL-68578 contenttype_h5p: Add name attribute to editor iframe The switch_to_class_iframe step needs a name attribute for the iframe. H5P third party library does not add that name attribute, so we add it. --- h5p/amd/build/editor_display.min.js | 2 +- h5p/amd/build/editor_display.min.js.map | 2 +- h5p/amd/src/editor_display.js | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/h5p/amd/build/editor_display.min.js b/h5p/amd/build/editor_display.min.js index 8d7d4429018..a33bad78949 100644 --- a/h5p/amd/build/editor_display.min.js +++ b/h5p/amd/build/editor_display.min.js @@ -1,2 +1,2 @@ -define ("core_h5p/editor_display",["exports","jquery"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){var c=(0,b.default)("#"+a),d=(0,b.default)(".h5p-editor"),e=d.closest("form"),f=(0,b.default)("h5p-editor-upload"),g=(0,b.default)("input[name=\"h5plibrary\"]"),h=(0,b.default)("input[name=\"h5pparams\"]"),i=(0,b.default)("input[name=\"name\"]"),j=(0,b.default)("input[name=\"h5paction\"]");j.val("create");H5PEditor.init(e,j,f,c,d,g,h,"",i,function cancelSubmitCallback(a){return a.is("[name=\"cancel\"]")})};a.init=c}); +define ("core_h5p/editor_display",["exports","jquery"],function(a,b){"use strict";Object.defineProperty(a,"__esModule",{value:!0});a.init=void 0;b=function(a){return a&&a.__esModule?a:{default:a}}(b);var c=function(a){var c=(0,b.default)("#"+a),d=(0,b.default)(".h5p-editor"),e=d.closest("form"),f=(0,b.default)("h5p-editor-upload"),g=(0,b.default)("input[name=\"h5plibrary\"]"),h=(0,b.default)("input[name=\"h5pparams\"]"),i=(0,b.default)("input[name=\"name\"]"),j=(0,b.default)("input[name=\"h5paction\"]");j.val("create");H5PEditor.init(e,j,f,c,d,g,h,"",i,function cancelSubmitCallback(a){return a.is("[name=\"cancel\"]")});document.querySelector("#"+a+" iframe").setAttribute("name","h5p-editor")};a.init=c}); //# sourceMappingURL=editor_display.min.js.map diff --git a/h5p/amd/build/editor_display.min.js.map b/h5p/amd/build/editor_display.min.js.map index 9560735de32..09d896b21d1 100644 --- a/h5p/amd/build/editor_display.min.js.map +++ b/h5p/amd/build/editor_display.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/editor_display.js"],"names":["init","elementId","editorwrapper","editor","mform","closest","editorupload","h5plibrary","h5pparams","inputname","h5paction","val","H5PEditor","cancelSubmitCallback","$button","is"],"mappings":"iJAwBA,uDAQO,GAAMA,CAAAA,CAAI,CAAG,SAACC,CAAD,CAAe,IACzBC,CAAAA,CAAa,CAAG,cAAE,IAAMD,CAAR,CADS,CAEzBE,CAAM,CAAG,cAAE,aAAF,CAFgB,CAGzBC,CAAK,CAAGD,CAAM,CAACE,OAAP,CAAe,MAAf,CAHiB,CAIzBC,CAAY,CAAG,cAAE,mBAAF,CAJU,CAKzBC,CAAU,CAAG,cAAE,4BAAF,CALY,CAMzBC,CAAS,CAAG,cAAE,2BAAF,CANa,CAOzBC,CAAS,CAAG,cAAE,sBAAF,CAPa,CAQzBC,CAAS,CAAG,cAAE,2BAAF,CARa,CAe/BA,CAAS,CAACC,GAAV,CAAc,QAAd,EAEAC,SAAS,CAACZ,IAAV,CACII,CADJ,CAEIM,CAFJ,CAGIJ,CAHJ,CAIIJ,CAJJ,CAKIC,CALJ,CAMII,CANJ,CAOIC,CAPJ,CAQI,EARJ,CASIC,CATJ,CAN6B,QAAvBI,CAAAA,oBAAuB,CAASC,CAAT,CAAkB,CAC3C,MAAOA,CAAAA,CAAO,CAACC,EAAR,CAAW,mBAAX,CACV,CAID,CAYH,CA7BM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module handles the display of the H5P authoring tool.\n *\n * @module core_h5p/editor_display\n * @package core_h5p\n * @copyright 2020 Victor Deniz \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\n/* global H5PEditor */\n\n/**\n * Display the H5P authoring tool.\n *\n * @param {String} elementId Root element.\n */\nexport const init = (elementId) => {\n const editorwrapper = $('#' + elementId);\n const editor = $('.h5p-editor');\n const mform = editor.closest(\"form\");\n const editorupload = $(\"h5p-editor-upload\");\n const h5plibrary = $('input[name=\"h5plibrary\"]');\n const h5pparams = $('input[name=\"h5pparams\"]');\n const inputname = $('input[name=\"name\"]');\n const h5paction = $('input[name=\"h5paction\"]');\n\n // Cancel validation and submission of form if clicking cancel button.\n const cancelSubmitCallback = function($button) {\n return $button.is('[name=\"cancel\"]');\n };\n\n h5paction.val(\"create\");\n\n H5PEditor.init(\n mform,\n h5paction,\n editorupload,\n editorwrapper,\n editor,\n h5plibrary,\n h5pparams,\n '',\n inputname,\n cancelSubmitCallback\n );\n};\n"],"file":"editor_display.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/editor_display.js"],"names":["init","elementId","editorwrapper","editor","mform","closest","editorupload","h5plibrary","h5pparams","inputname","h5paction","val","H5PEditor","cancelSubmitCallback","$button","is","document","querySelector","setAttribute"],"mappings":"iJAwBA,uDAQO,GAAMA,CAAAA,CAAI,CAAG,SAACC,CAAD,CAAe,IACzBC,CAAAA,CAAa,CAAG,cAAE,IAAMD,CAAR,CADS,CAEzBE,CAAM,CAAG,cAAE,aAAF,CAFgB,CAGzBC,CAAK,CAAGD,CAAM,CAACE,OAAP,CAAe,MAAf,CAHiB,CAIzBC,CAAY,CAAG,cAAE,mBAAF,CAJU,CAKzBC,CAAU,CAAG,cAAE,4BAAF,CALY,CAMzBC,CAAS,CAAG,cAAE,2BAAF,CANa,CAOzBC,CAAS,CAAG,cAAE,sBAAF,CAPa,CAQzBC,CAAS,CAAG,cAAE,2BAAF,CARa,CAe/BA,CAAS,CAACC,GAAV,CAAc,QAAd,EAEAC,SAAS,CAACZ,IAAV,CACII,CADJ,CAEIM,CAFJ,CAGIJ,CAHJ,CAIIJ,CAJJ,CAKIC,CALJ,CAMII,CANJ,CAOIC,CAPJ,CAQI,EARJ,CASIC,CATJ,CAN6B,QAAvBI,CAAAA,oBAAuB,CAASC,CAAT,CAAkB,CAC3C,MAAOA,CAAAA,CAAO,CAACC,EAAR,CAAW,mBAAX,CACV,CAID,EAYAC,QAAQ,CAACC,aAAT,CAAuB,IAAMhB,CAAN,CAAkB,SAAzC,EAAoDiB,YAApD,CAAiE,MAAjE,CAAyE,YAAzE,CACH,CA9BM,C","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module handles the display of the H5P authoring tool.\n *\n * @module core_h5p/editor_display\n * @package core_h5p\n * @copyright 2020 Victor Deniz \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport $ from 'jquery';\n/* global H5PEditor */\n\n/**\n * Display the H5P authoring tool.\n *\n * @param {String} elementId Root element.\n */\nexport const init = (elementId) => {\n const editorwrapper = $('#' + elementId);\n const editor = $('.h5p-editor');\n const mform = editor.closest(\"form\");\n const editorupload = $(\"h5p-editor-upload\");\n const h5plibrary = $('input[name=\"h5plibrary\"]');\n const h5pparams = $('input[name=\"h5pparams\"]');\n const inputname = $('input[name=\"name\"]');\n const h5paction = $('input[name=\"h5paction\"]');\n\n // Cancel validation and submission of form if clicking cancel button.\n const cancelSubmitCallback = function($button) {\n return $button.is('[name=\"cancel\"]');\n };\n\n h5paction.val(\"create\");\n\n H5PEditor.init(\n mform,\n h5paction,\n editorupload,\n editorwrapper,\n editor,\n h5plibrary,\n h5pparams,\n '',\n inputname,\n cancelSubmitCallback\n );\n document.querySelector('#' + elementId + ' iframe').setAttribute('name', 'h5p-editor');\n};\n"],"file":"editor_display.min.js"} \ No newline at end of file diff --git a/h5p/amd/src/editor_display.js b/h5p/amd/src/editor_display.js index 8b89e4f7de1..e27dcff01e2 100644 --- a/h5p/amd/src/editor_display.js +++ b/h5p/amd/src/editor_display.js @@ -59,4 +59,5 @@ export const init = (elementId) => { inputname, cancelSubmitCallback ); + document.querySelector('#' + elementId + ' iframe').setAttribute('name', 'h5p-editor'); }; From 45bff7f9d66e40e7b2ce7ae2ccfbe9b5862e0198 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Tue, 26 May 2020 15:11:50 +0200 Subject: [PATCH 3/3] MDL-68578 contenttype_h5p: Behat test for H5P editor changes --- contentbank/tests/behat/edit_content.feature | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/contentbank/tests/behat/edit_content.feature b/contentbank/tests/behat/edit_content.feature index 713768c1f5a..aef6eab5386 100644 --- a/contentbank/tests/behat/edit_content.feature +++ b/contentbank/tests/behat/edit_content.feature @@ -97,3 +97,21 @@ Feature: Content bank use editor feature | moodle/contentbank:useeditor | Prohibit | editingteacher | System | | And I reload the page Then "[data-action=Add-content]" "css_element" should not exist + + Scenario: Users can edit content and save changes + Given the following "contentbank content" exist: + | contextlevel | reference | contenttype | user | contentname | filepath | + | System | | contenttype_h5p | admin | filltheblanks.h5p | /h5p/tests/fixtures/filltheblanks.h5p | + And I click on "Site pages" "list_item" in the "Navigation" "block" + And I click on "Content bank" "link" in the "Navigation" "block" + And I click on "filltheblanks.h5p" "link" + And I click on "Edit" "link" + And I switch to "h5p-editor-iframe" class iframe + And the field "Title" matches value "Geography" + And I set the field "Title" to "New title" + And I switch to the main frame + When I click on "Save" "button" + And I should see "filltheblanks.h5p" in the "h1" "css_element" + And I click on "Edit" "link" + And I switch to "h5p-editor-iframe" class iframe + Then the field "Title" matches value "New title"