Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
There is UI and functionality issue come when aggregation enabled
download H5P 2.x and apply patch for Drupal 10 combability and make sure "admin/config/development/performance" aggregation enabled.
May be this issue come with jQuery version 2.x using jQuery v1.9.1 need to upgrade jQuery 3.x or higher version with Drupal 10 compatibility
After enable aggregation js/css not apply into iframe content
Comment | File | Size | Author |
---|---|---|---|
#17 | 3372528-h5p-assets-fix-17.patch | 3.35 KB | jhuhta |
#13 | 3372528-13.patch | 3.09 KB | googletorp |
#8 | fixed_asset_optimization_issue-3372528-8.patch | 17.42 KB | StanleyFernandes |
#6 | fixed-asset-optimization-issue.patch | 4.55 KB | pjotr.savitski |
Issue fork h5p-3372528
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ajeet_kumarComment #3
pjotr.savitski CreditAttribution: pjotr.savitski as a volunteer commentedThe assumption about this having something to do with jQuery is incorrect as H5P uses custom versions of everything, at least within internal iframes.
This is the issue of createCachedPublicFiles method of the H5PDrupal class.
This line will throw an error as the second argument is required (at least with PHP 8.1):
The logic tells that it should be changed to:
Which fixes the exception being thrown, but the end result is not what it is expected to be. This line will fail as there is no data key or it is empty, instead items are set and those point to the original files provided:
I'm not sure about the inner workings of the new JsCollectionOptimizerLazy class (or the one before that) and why this new lazy approach and creation of those files at the first request fails, but this is what is causing the issue. I've tried proving a library name and that gets the expected data key returned, but the files themselves are never created and the logger reports The libraries to include are encoded incorrectly.
My guess is that something has changed and the data provided for optimization is formatted incorrectly, though I see no documentation on how that should be formatted or what changed with the move to the new lazy approach.
The only really quick fix is to always disregard the JS and CSS preprocess configuration option, but that makes the whole optimization step meaningless. Just change the aggregateAssets method from this (this still keeps aggregation functional for everything else but the H5P):
to this:
Comment #4
pjotr.savitski CreditAttribution: pjotr.savitski as a volunteer commentedI've checked the code and it seems that individual files are not really processed in any way, at least not with the type of file, unless at least one library is provided. This more or less means that the whole optimization code is useless, unless libraries are used, which is not really applicable in this case.
Not sure is this is the new internal logic or not, but providing any library prevents the aggregated file from being created. The other issue is that there is no cache busting logic present like it used to be with the previous approach and recreation of the combined file using fresh versions of the resources each time new cache file is generated.
It is possible to define services for old versions of both JS and CSS optimizer classes, though both are marked s deprecated and will be removed in version 11. Another way would be to create a custom solution based on previous versions of classes and use that instead, though that would have to get the cleanup procedures for unused versions of asset files and handling of handling of caches being cleared.
Long story short - new solution will not work with custom JS and CSS files. Declaring custom services based on now deprecated classes worked for JS part, yet styles were not loaded correctly (at least in my case). It seems that the only viable solution left is to create a custom optimizer logic that would just mimic the one that worked earlier and combine the file groups into one file, while keeping track of such files and removing the old versions.
It seems that new solution is purely based on libraries and does not really work on any of the custom resources like the previous one did. The new approach uses AssetResolver class that will be provided the names of the libraries and libraries only, extracted by the corresponding controller of the system module. Any custom assets are not really welcome by the optimizer and the behavior with not providing any libraries that does not process any of the custom individual files seems to be the correct one, as those are not considered for optimization or something along the lines.
Comment #5
pjotr.savitski CreditAttribution: pjotr.savitski as a volunteer commentedIt seems that a few modifications can help with getting the old way of dealing with assets running again. It requires redefining and using old versions of collection optimizer services. A few modifications to the current code would also be required as there are some changes in how new approach works, including changes to the dependencies (mostly affects the CSS, at least it was like that for me).
First, a h5p.services.yml file needs to be added, having copies of services from Drupal version 9.5 with a legacy suffix:
Secondyl H5PDrupal.php file has to be patched with changes to aggregatedAssets and createCachedPublicFiles methods:
This seems to be making everything work as expected, at least my testing material looks the way it used to and has no JS errors. It might be able to work until Drupal version 11.
The best approach would be to use the new logic and somehow dynamically define a library for each of the material, thus making the new lazy approach work as expected. One way would be to pass a library called h5p-content- and then dynamically define that library with the hook if the current context is one of the controllers for JS and CSS asset optimizers and the query string has some custom keys present. There might be a better approach, but this is what has come to my mind. Another possibility would be to mimic the new lazy approach and have a custom controllers that create optimized asset files or serve already existing ones.
Comment #6
pjotr.savitski CreditAttribution: pjotr.savitski as a volunteer commentedHere is the patch that uses old versions of JS and CSS optimisation services with a few additional fixes for related problems of missing keys and warnings.
Comment #7
o_timoshchuk CreditAttribution: o_timoshchuk at DevBranch, Drupal Ukraine Community, Evolving Web commented+1 RTBC I applied patch #6 with the Drupal 10 compatibility patch. It is functioning correctly.
Comment #8
StanleyFernandesPatch #6 failed with the latest D10 compatibility patch of h5p i.e
https://www.drupal.org/project/h5p/issues/3329297#comment-15218847
With the help of patch #6 created a new patch.
h5p version 2.0.0-alpha3
Tested on Drupal 10.1.5.
Comment #9
Anaconda777 CreditAttribution: Anaconda777 commentedThis #8 patch does not apply with the latest dev.
And with 2.0.0-alpha3 I am not able to get it working with D10 properly, cos I dont know which patches it is missinge compared to dev?
Comment #10
SirClickalotI can confirm too that, when using the latest dev version
"drupal/h5p": "2.0.x-dev@dev"
, that most, but not all H5P creations DO NOT render when JavaScript aggregation is active.By contrast to @Anaconda777's comment, mine DO all seem to work with CSS aggregation active; it is only the JavaScript aggregation.
Comment #11
Ammaletu CreditAttribution: Ammaletu at Zebralog commentedAgainst the current dev version patch #6 almost works. The changes in src/H5PDrupal/H5PDrupal.php in line 88, 89 and 94 don't apply, I think. After I changed these lines manually, displaying the H5P content worked again. Patch #8 contains a lot of the changes to get H5P to work with Drupal 10, which are in some way already part of the dev version, soon to be tagged as alpha4.
Comment #12
catchThese needs a re-roll.
Comment #13
googletorp CreditAttribution: googletorp as a volunteer and at Reveal IT commentedRerolled the patch from #8 by manual comparing what was required.
Comment #14
Anaconda777 CreditAttribution: Anaconda777 commented@googletrop Thanks, that patch applies but now when viewing H5P content I get wsod and this:
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "asset.js.collection_optimizer_legacy". Did you mean one of these: "asset.css.collection_optimizer", "asset.js.collection_optimizer"? i Drupal\Component\DependencyInjection\Container->get() (rad 157 av /var/www/html/drupal10/web/core/lib/Drupal/Component/DependencyInjection/Container.php).
I have Drupal 10.1.6
Without this patch there is not error message, it just does not show the H5P content when js aggregation is on
Comment #15
catchThe reroll is missing the two legacy services added in the previous patches.
Comment #16
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedNow that #3329297: Automated Drupal 10 compatibility fixes has landed, the patch #6 should be re-rolled.
Comment #17
jhuhta CreditAttribution: jhuhta at Siili Solutions commentedThis is a reroll based on #8.
Comment #19
catchCommitted/pushed to 2.0.x so that this change is available with the dev release. Thanks!
Comment #20
catchActually no this isn't good either, it makes the H5P module only compatible with Drupal 10.1, not 9.5 or 10.0.x, because the legacy classes don't exist in those versions. Also using the legacy services is a stopgap anyway.
Two options:
1. Define the services in a service provider instead of YAML so it can check for the class existence first. Then in the actual logic, check the Drupal core version and only use the legacy services if we're on 10.1.x or higher. This adds more complexity and is still a stopgap.
2. Refactor this entirely to either not aggregate, or to not use the the Drupal core aggregation API at all and just concatenate the files together instead - or at least use more targeted bits of the API.
Comment #21
Anaconda777 CreditAttribution: Anaconda777 commentedcan confirm, patch #17 works with D10.1.6 and latest H5P dev
Thanks / kiitos
Comment #22
catchI was wrong in #20, because the 'legacy' classes are just the old one shipped with 9.5/10.0, then this approach works fine as a stopgap and should be compatible with both 9.5/10.0/10.1.
I opened #3401541: Refactor asset aggregation to avoid using deprecated asset optimization classes to refactor things in time for Drupal 11 compatibility though. Moving this issue back to fixed.