Adding .h5p activities programmatically to D8 nodes

Created on 7 February 2020, almost 5 years ago
Updated 1 August 2023, over 1 year ago

I am running Drupal 8.8 on my local computer and have a custom module and a custom content type with a H5P content field. I also have about 2000 h5p fill-in-the-blanks (Blanks) activities in .h5p zip archives. How can I upload those .h5p files into a programmatically, newly created node.

I have tried to use the following code:

$H5PObj = H5PDrupal::getInstance();  
$result = $H5PObj->insertContent($h5p_content, $contentMainId = NULL);

I identified three tables that seemed to be important for h5P activities: h5p_content, h5p_content_libraries, and node__field_[field_name]. But even with the data in those tables the h5p activity still wasn't added to the field in the node.

Am I missing something (a table)? Do I need to call another function aside from insertContent()?

💬 Support request
Status

Active

Component

Miscellaneous

Created by

🇺🇸United States nsuit

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India ushma

    Hi
    I am able to save h5p content using above method but its not showing up properly in front end. I found out that there is no entry in h5p_content_libraries table for the new h5p content id created using H5PContent::create(). What am I missing here ?

Production build 0.71.5 2024