For some time now, it is possible to include external H5P activities in Moodle via the text editor (H5P button). You just have to upload your H5P file and Moodle handles the rest. Moodle uses a filter to transform the H5P file URL to an iframe when loading the course. In order to adjust the height of the iframe, the filter when building the HTML that generates the iframe, also adds a script tag with its own resizer javacript code (resizer.js). To avoid loading the JS file multiple times when there are several H5P iframes, the filter checks if the script has already been loaded once (via a static prop in the filter_displayh5p class).
Here is what it looks like in a course. You have to scroll in the label, not very practical.
Why is this happening for this course format and not the others?
It took me some time to understand it but it has to do with the way the content for a card is generated in this plugin. In the card_one_section_renderable.php file, more specifically in the get_activities_details method which is responsible to get the content that will be displayed in the card, either as a summary or the full content for labels and folders, the content is generated twice, once for the summary prop and once for the fullcontent prop. By calling $this->courseformatdatacommontrait->course_section_cm_text($mod, $displayoptions) twice, the H5P iframe is generated twice, once with the resizer script and the second time without. The problem is, it’s the second call which will be set as fullcontent (for labels and folders), resulting in a lack of resizer script when displayed in the template.
To solve this, $this->courseformatdatacommontrait->course_section_cm_text($mod, $displayoptions) should only be called once and stored in a temporary variable which will then be used to set the summary and the fullcontent props.
Not knowing how this plugin fully works, there might be others places where this change needs to be done, not only the card_one_section_renderable.php file ?
Hello,
For some time now, it is possible to include external H5P activities in Moodle via the text editor (H5P button). You just have to upload your H5P file and Moodle handles the rest. Moodle uses a filter to transform the H5P file URL to an iframe when loading the course. In order to adjust the height of the iframe, the filter when building the HTML that generates the iframe, also adds a script tag with its own resizer javacript code (resizer.js). To avoid loading the JS file multiple times when there are several H5P iframes, the filter checks if the script has already been loaded once (via a static prop in the
filter_displayh5p
class).Here is what it looks like in a course. You have to scroll in the label, not very practical.
Why is this happening for this course format and not the others?
It took me some time to understand it but it has to do with the way the content for a card is generated in this plugin. In the
card_one_section_renderable.php
file, more specifically in theget_activities_details
method which is responsible to get the content that will be displayed in the card, either as a summary or the full content for labels and folders, the content is generated twice, once for the summary prop and once for the fullcontent prop. By calling$this->courseformatdatacommontrait->course_section_cm_text($mod, $displayoptions)
twice, the H5P iframe is generated twice, once with the resizer script and the second time without. The problem is, it’s the second call which will be set as fullcontent (for labels and folders), resulting in a lack of resizer script when displayed in the template.To solve this,
$this->courseformatdatacommontrait->course_section_cm_text($mod, $displayoptions)
should only be called once and stored in a temporary variable which will then be used to set the summary and the fullcontent props.Not knowing how this plugin fully works, there might be others places where this change needs to be done, not only the
card_one_section_renderable.php
file ?Thank you