"H5P Editor undefined"

Forums: 

Hello,

I need help because I am stuck on a problem:
I use the default Docker environment from the tutorials and Version H5P Plugin Version 7.5  and I can create my own H5P content with it.  But if I need to create e.g. a widget and for that I need the H5PEditor variable,e.g. in the following code line:

`H5PEditor.widgets.python_widget = PythonWidget;`

then the H5PEditor variable is empty and accordingly I cannot store anything in the widgets attribute.

I have already tried different things: Rebuilt Docker, changed the structure of the H5P plugin, but slowly I have no idea where the error could be.... Here is the current code of the widget, which I have oriented to otackes boilerplate: https://codeberg.org/a_siebel/h5p-editor-python-widget

 

otacke's picture

Hi!

You have amended the `entries` file of the boilerplate template and you're setting a local variable named `H5PEditor` (see https://codeberg.org/a_siebel/h5p-editor-python-widget/src/branch/master/src/entries/h5peditor-python-widget.js#L6) which will then will be used instead of accessing the "real" `H5PEditor` variable which is `window.H5PEditor`.

Cheers,
Oliver

Thanks for your help

I wrote this line for testing purposes.

Unfortunatly H5PEditor is not set in window, see screenshot.

Attachments: 
otacke's picture

If it's not set, then the question is how you are instantiating the editor widget in the first place?

I must admit, that I don't know where the H5PEditor-Object should be instantiated.

In your widget-boilerplate (https://github.com/otacke/h5p-editor-boilerplate/blob/master/src/entries...(line 5)), you add the Widget Class to the H5PEditor attribute `widgets` - , I tried the same, but it fails because the H5PEditor-object is not defined.. I can't find any places in tutorials/other plugins where the H5PEditor object is instanciated, so I thought it is a 'magic' global variable like `H5P` and `H5PIntegration`.

otacke's picture

Hi!

I was not asking where H5PEditor was instantiated (H5P core does that, nothing you do manually), but how you instantiated your editor widget. Editor widgets need to be added to an editor field in semantics.json via the `widget` property - and if your widget was started that way, H5PEditor would be present as that's what interprets semantics.json.

Cheers,

Oliver 

This can be found in the semantics.json of the plugin that should use the widget.

otacke's picture

The issue seems to be in your `library.json` definition of that other library. Editor widgets do not belong in the `preloadedDependencies`. That's where libraries are put if the content type's view requires them, not the content type's editor.

So, if your intention is to present whatever your are creating to the user/learner, then you don't need an editor widget for that. If your intention is to present whatever you are creating to the author, then an editor widget is what you need, but it needs to be referenced in an `editorDependencies` section within `library.json`.

I can't tell you how grateful I am!

I tried everything for days, but I didn't notice this small but important difference.

Thank you!!!

otacke's picture

Don't mention it :-) And actually this is not documented on https://h5p.org/library-definition but hidden on https://h5p.org/creating-editor-widgets ...