Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion admin/class-h5p-editor-wordpress-storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public function getLibraries($libraries = NULL) {
*/
public function alterLibraryFiles(&$files, $libraries) {
$plugin = H5P_Plugin::get_instance();
$plugin->alter_assets($files, $libraries, 'editor');
$custom_script_parameters = (object) array();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@otacke do we have a standard for this? I noticed in the other PR https://github.com/h5p/h5p-wordpress-plugin/pull/218/changes#diff-136c1cb88ba22448ea89193777a49f07d2f68706fabd465e66c230d05f831799R1279 you are using [] modern array syntax but here is old school array() are we adhering some sort of non defacto standard? like using array() for initializers but using [] for other scopes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arzola Good catch. H5P Group does not have guidelines for PHP, no phpcs.xml or similar. I then usually fall back to using what the surrounding code dictates.

Cmp. h5p/h5p-php-library#290 (comment)

$plugin->alter_assets($files, $libraries, 'editor', $custom_script_parameters);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion admin/class-h5p-plugin-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,11 @@ public function embed() {
// Get content assets
$preloaded_dependencies = $core->loadContentDependencies($content['id'], 'preloaded');
$files = $core->getDependenciesFiles($preloaded_dependencies);
$plugin->alter_assets($files, $preloaded_dependencies, 'external');
$custom_script_parameters = (object) array();
$plugin->alter_assets($files, $preloaded_dependencies, 'external', $custom_script_parameters);
if (is_object($custom_script_parameters) && !empty((array) $custom_script_parameters)) {
$integration['customScriptParameters'] = $custom_script_parameters;
}

$scripts = array_merge($scripts, $core->getAssetsUrls($files['scripts']));
$styles = array_merge($styles, $core->getAssetsUrls($files['styles']));
Expand Down
17 changes: 14 additions & 3 deletions public/class-h5p-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,16 @@ public function add_assets($content, $no_cache = FALSE) {
// Get assets for this content
$preloaded_dependencies = $core->loadContentDependencies($content['id'], 'preloaded');
$files = $core->getDependenciesFiles($preloaded_dependencies);
$this->alter_assets($files, $preloaded_dependencies, $embed);

// Optional script parameters that custom user scripts should be able to access
$custom_script_parameters = (object) array();

$this->alter_assets($files, $preloaded_dependencies, $embed, $custom_script_parameters);

if ((is_object($custom_script_parameters)) && !empty((array)$custom_script_parameters)) {
// Allow to access custom user script paramters via H5PIntegration
self::$settings['customScriptParameters'] = $custom_script_parameters;
}

/*
* Cached assets were broken by faulty folder structure in 1.17.0 - 1.17.3
Expand Down Expand Up @@ -1170,8 +1179,9 @@ public function add_assets($content, $no_cache = FALSE) {
* @param array $dependencies
* @param array $files scripts & styles
* @param string $embed type
* @param object &$custom_script_parameters Custom parameters that should be available to JavaScript
*/
public function alter_assets(&$files, &$dependencies, $embed) {
public function alter_assets(&$files, &$dependencies, $embed, &$custom_script_parameters = null) {
if (!has_action('h5p_alter_library_scripts') && !has_action('h5p_alter_library_styles')) {
return;
}
Expand All @@ -1194,8 +1204,9 @@ public function alter_assets(&$files, &$dependencies, $embed) {
* @param array &$scripts List of JavaScripts to be included.
* @param array $libraries The list of libraries that has the scripts.
* @param string $embed_type Possible values are: div, iframe, external, editor.
* @param object &$custom_script_parameters Custom parameters that should be available to JavaScript
*/
do_action_ref_array('h5p_alter_library_scripts', array(&$files['scripts'], $libraries, $embed));
do_action_ref_array('h5p_alter_library_scripts', array(&$files['scripts'], $libraries, $embed, &$custom_script_parameters));

/**
* Allows you to alter which stylesheets are loaded for H5P. This is
Expand Down