Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

H5P editor class.

Copyright: 2020 Victor Deniz <victor@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 487 lines (17 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: editor  - X-Ref

H5P editor class, for editing local H5P content.

__construct()   X-Ref
Inits the H5P editor.


set_content(int $id)   X-Ref
Loads an existing content for edition.

If the H5P content or its file can't be retrieved, it is not possible to edit the content.

param: int $id Id of the H5P content from the h5p table.
return: void

set_library(string $library, int $contextid, string $component, string $filearea,?int $itemid = 0, string $filepath = '/', ?string $filename = null, ?int $userid = null)   X-Ref
Sets the content type library and the file area to create a new H5P content.

Note: this method must be used to create new content, to edit an existing
H5P content use only set_content with the ID from the H5P table.

param: string $library Library of the H5P content type to create.
param: int $contextid Context where the file of the H5P content will be stored.
param: string $component Component where the file of the H5P content will be stored.
param: string $filearea File area where the file of the H5P content will be stored.
param: int $itemid Item id file of the H5P content.
param: string $filepath File path where the file of the H5P content will be stored.
param: null|string $filename H5P content file name.
param: null|int $userid H5P content file owner userid (default will use $USER->id).
return: void

set_filearea(int $contextid, string $component, string $filearea,int $itemid, string $filepath = '/', ?string $filename = null, ?int $userid = null)   X-Ref
Sets the Moodle file area where the file of a new H5P content will be stored.

param: int $contextid Context where the file of the H5P content will be stored.
param: string $component Component where the file of the H5P content will be stored.
param: string $filearea File area where the file of the H5P content will be stored.
param: int $itemid Item id file of the H5P content.
param: string $filepath File path where the file of the H5P content will be stored.
param: null|string $filename H5P content file name.
param: null|int $userid H5P content file owner userid (default will use $USER->id).
return: void

add_editor_to_form(MoodleQuickForm $mform)   X-Ref
Adds an H5P editor to a form.

param: MoodleQuickForm $mform Moodle Quick Form
return: void

save_content(stdClass $content)   X-Ref
Creates or updates an H5P content.

param: stdClass $content Object containing all the necessary data.
return: int Content id

update_h5p_file(stdClass $content)   X-Ref
Creates or updates the H5P file and the related database data.

param: stdClass $content Object containing all the necessary data.
return: void

add_assets_to_page()   X-Ref
Add required assets for displaying the editor.

return: void

get_editor_translations(string $language)   X-Ref
Get editor translations for the defined language.
Check if the editor strings have been translated in Moodle.
If the strings exist, they will override the existing ones in the JS file.

param: string $language The language for the translations to be returned.
return: array The editor string translations.

data_preprocessing()   X-Ref
Preprocess the data sent through the form to the H5P JS Editor Library.

return: stdClass