Hook_h5p_styles_alter not working on first step of activity creation

Created on 8 September 2020, almost 5 years ago
Updated 25 July 2025, 18 days ago

I am able to assign a css file to the H5P editor iframe using hook_h5p_styles_alter through a module as documented in h5p.api.php. It works fine while editing or modifying an activity, but apparently it does not for the first step of the creation process, when asked to select a H5P activity type ("content type"). However, as soon as I click on one of them and its editor form loads, the css file is finally called and visible using the browser inspector for that iframe.

Once created, if I edit the activity everything works directly. That's why I point to the Activity Content Selector step.

I am not using conditions inside the hook:

function h5p_css_h5p_styles_alter(&$styles, $libraries, $mode) {
    $styles[] = (object) array(
      'path' => drupal_get_path('module', 'h5p_css') . '/css/h5p_css.css',
      'version' => '?ver=1',
    );
}
πŸ› Bug report
Status

Active

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain robegb

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.

  • πŸ‡ΊπŸ‡ΈUnited States illeace

    The documented purpose of hook_h5p_styles_alter() is to allow you to add additional styles to H5Ps. This first step of the creation process you describe is when the H5P hub is visible, but you have not yet selected which H5P type you'd like to use. Once you've selected a specific H5P, then that H5P is loaded and the Drupal module calls this hook so it can include any custom CSS you've specified. This seems like the intended behavior so I think this is working as designed.

  • πŸ‡ΊπŸ‡ΈUnited States sim_1

    Closing. Thank you!

Production build 0.71.5 2024