H5PMod : Apply to all h5p libraries

Forums: 

Hello,

I'm looking for code that will apply custom.css to all the H5P libraries that are installed in Moodle.

The default code below only add custom.css to interative video : 

Thank you! 

    public function hvp_alter_styles(&$styles, $libraries, $embedType) {
        global $CFG;
        if (
            isset($libraries['H5P.InteractiveVideo']) &&
            $libraries['H5P.InteractiveVideo']['majorVersion'] == '1'
        ) {
            $styles[] = (object) array(
                'path'    => $CFG->httpswwwroot . '/theme/h5pmod/style/custom.css',
                'version' => '?ver=0.0.1',
            );
        }
    }

    /**
     * Add scripts when an H5P is displayed.
     *
     * @param object $scripts Scripts that will be applied.
     * @param array $libraries Libraries that will be displayed.
     * @param string $embedType How the H5P is displayed.
     */
    public function hvp_alter_scripts(&$scripts, $libraries, $embedType) {
        global $CFG;
        if (
            isset($libraries['H5P.InteractiveVideo']) &&
            $libraries['H5P.InteractiveVideo']['majorVersion'] == '1'
        ) {
            $include_file = ($embedType === 'editor' ? 'customEditor.js' : 'custom.js');
            $scripts[] = (object) array(
                'path'    => $CFG->httpswwwroot . '/theme/h5pmod/js/' . $include_file,
                'version' => '?ver=0.0.1',
            );
        }
    }
icc's picture

You should be able to do so by changing the code to this:

public function hvp_alter_styles(&$styles, $libraries, $embedType) {
    global $CFG;

    $styles[] = (object) array(
        'path'    => $CFG->httpswwwroot . '/theme/h5pmod/style/custom.css',
        'version' => '?ver=0.0.1',
    );
}
 

Thank you! It's working.