Get Exercise content

Forums: 

Hi, 
I'm working on one custom module for Drupal 7 & 8. And I need to get the exercise content like exercise instruction.
How can I take that in Javascript code ?

otacke's picture

Hi Kilian!

It'd help to know to what end you'd like to get the parameters.

If you need them without the content running, you could retrieve them from the database using AJAX. You can find them inside the table h5p_nodes (on Drupal 7, certainly something similar on Drupal 8) in the fields filtered and json_content (the same as filtered but possibly containing invalidated data that will have been stripped out in filtered)

If you need them before content is instantiated, you could retrieve them using the alter_params hook (https://git.drupalcode.org/project/h5p/blob/HEAD/h5p.api.php). You could read/modify them there before they are passed to the content type (but in PHP).

If you want to read them when content is running, the wrapping window context of the H5P iframe will contain the H5PIntegration object that holds an array of all contents that are displayed in an array contents that itself holds all the content objects with info on them, in particular the jsonContent property with the parameters.

If you want to modify them while the content is running, you'll have to use the H5P object within each H5P iframe that holds the instances array with all contents running inside, but then there's no fixed scheme. You'd have to maneuver your way through the contents' JavaScript to find and modify the values when running.

Best,
Oliver