Previous state without plugin

Forums: 

Hello H5P community,

I'm using https://github.com/h5p/h5p-drag-text/ content types, I'm trying to extend this library to handle a previous state without using Drupal or WordPress plugin. I want to retrieve data from Local Storage (actually) and pass it as a previous state to my content Drag the text. Is this something possible with xAPI or anything else ? Didn't find any informations about it ... thanks for helping.

Cheers.

Summary: 
Pass previous state without using any plugins (Drupal, WordPress, ...)
Content types: 
otacke's picture

Hi rlefort123!

If you're able to modify the parameters that the content types get from your solution: sure.

In order to retrieve the data, you only need to call getCurrentState() on content types (that implement it). Content types then expect the return value in the extras argument (as previousState) of their constructor function when they are instantiated.

Best,

Oliver 

Hi otacke, thanks for your reply !

I'm new to H5P and I have to admit, I'm struggling to invoke the constructor with a previous state :(
Do you have any clues please ?

Best.

otacke's picture

Hi!

That's a little hard without knowing anything about what you're doing, but the syntax basically is:

constructor(params, contentId, extras)

where

  • params is the json object containing the configuration entered in the editor and that's retrieved from the database (or wherever it may be stored in your case),
  • contentId is the unique number of the content, and
  • extras is an object that can hold individual configurations, most notably a the metadata object and the previousState object.

Essentially, wherever you call the constructor function of the content type, you need to pass something like

{
  previousState: foo
}

where foo is the value that was returned by getCurrentState().

Best,
Oliver