Closed (fixed)
Project:
H5P - Create and Share Rich Content and Applications
Version:
2.0.x-dev
Component:
Code
Priority:
Major
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
13 Sep 2022 at 13:12 UTC
Updated:
2 Oct 2025 at 19:34 UTC
Jump to comment: Most recent
Comments
Comment #2
catchBumping this to major because it means that fully updating to H5P 1.25 requires an update to the vendor directory. I've committed an issue that allows update via composer, but that makes the app vendor directory out of sync with the module one #3411479: Allow update to H5P editor/core 1.25.
H5P uses some css/js from this directory though, so it's not as easy as deleting it, those would have to be included another way. A possible solution would be a build step for the module to extract those files from h5p core and add them in a css/js vendor directory without any of the PHP code though. Maybe just be deleting the PHP files from /vendor?
Comment #3
shaundychkoThe /h5p/vendor/ directory can't really be deleted since not only are so many CSS and JS files referenced in code, but it's also in the resize JS link in embeds, so removing it would somewhat break other sites that have embedded an H5P. Also, the composer.json needs to lock down a specific version of the dependencies in order to have a match between the dependencies included in the module's /vendor and the dependencies installed by composer in the project's root /vendor. The merge request in #3420268: Support h5p/h5p-core:1.26 and h5p/h5p-editor:1.25 deletes the autoloader and all php files included in the module, and keeps the composer.lock file in order for the version installed in the project /vendor to match the CSS and JS shipped with the module's /vendor directory.
Comment #6
shaundychkoMerge request 27 removes the vendor directory and adds a build step using a custom Drush command
drush h5p:copy-assetsto copy assets, such as JS and CSS, to./assets/h5p-coreand./modules/h5peditor/assets/h5p-editor. The Drush command outputs every source/destination copied. The Readme.md is updated to document the Drush command.This MR doesn't deal with updating the version of the h5p dependencies. It focuses exclusively on removing the vendor directory and creating a post-install build step using Drush.
The issue of "resize JS link in embeds" was ignored. Sites with that feature can create redirects to fix it.
Comment #7
nicholass@shaundychko
So were on the latest alpha, I then require dev so I can test your patch, but I also need the patch from #3497789 but no matter what order I can't apply both patches. What am I doing wrong, since https://www.drupal.org/project/h5p/issues/3497789#comment-15941539 makes it sound like it should work.
Here is my patch in composer, I can't get both to work
Comment #8
nicholassOk I think I found my answer https://www.drupal.org/project/h5p/issues/3499799
Comment #9
nicholassComment #10
catchDon't really think the module can require a separate drush build step after every composer update/install.
What about a script that deletes all files from the vendor/ directory except the CSS/JS?
That way the runtime code doesn't have to change, but the PHP would no longer be in the folders. This would then have to be run when releases are made by the maintainers, but not by individual users of the module.
It might also be worth filing an upstream issue against h5p itself to ask them to split the PHP and css/js assets into two separate repositories, then the CSS/JS could be brought in with libraries module are similar standard approaches.
drupal/core-vendor-hardeningmight have ideas to borrow for removing all the php files.Comment #11
frobCould we use
getInstallPathto move the files to the public directory at runtime. We might need to use hook_library_info_alter to set the drupal library to the correct public file path.Comment #12
frobI was recently told about another module that provides functionality for exactly this. The Vendor stream wrapper module provides an API to allow modules to include css/etc through a drupal route. Looks promising, but, if we want to use Drupal's library system we might still need to use hook_library_info_alter.
Comment #13
frobComment #14
frobFirst pass was a bust. The css included in the package has some relative urls that didn't play well with the Vendor Stream Wrapper module. I am shifting to another approach based on the same mechanism as the asset injector module. Essentially, I will copy the files into the default assets stream wrapper and serve them directly from there.
Comment #15
frobI have gone ahead and rebased the branch and rebuilt it to automatically copy the js/css/etc into the assets://h5p files location. Things are working pretty well. I have run into one issue with the language support. It doesn't seem to find the language js files.
Comment #16
catchHaven't done a full review yet but +1 to copying the assets across. Does the MR so far handle deleting the assets and copying them again so they can be updated?
Comment #17
frobThey should be overwritten when recopied so deletion shouldn't be necessary. That should handle any updates to the h5p packages. The files themselves are already tightly coupled, so if an update to h5p-core or h5p-editor happens that changes the files we would need to deal with that update specifically anyway.
Something that this brought to light are some optimizations that aught to be done, in another issue, regarding the embedding. There is also a php file that was being included
embed.php. I is basically just a template. It would be nice if, up stream, this file got turned into a callback or, maybe, we turn it into a twig template.The change I made is to use this
embed.phpfile directly from the vendor.I created #3546025: Use a twig template instead of capturing the output of embed.php to handle the embed issue.
Comment #20
msandoval commentedThis issue is now ready for review.
Some issues that came up during development that bear special scrutiny:
Comment #21
illeace commentedThis looks good, marking RTBC. Things that have been tested in both Drupal 10 and Drupal 11:
Check asset mirroring works:
Check paths have been updated:
Aggregation
Comment #24
sim_1Thanks everyone for all your work on this big MR. Merged and marking as fixed.