Problem/Motivation
Drupal is moving to object oriented hooks, which offer better performance, and support dependency injection for better type safety and service mocking for testing.
Object oriented hooks are fully supported in Drupal 11, but there are backwards compatible using the #[LegacyHook], but only as far as 10.1, as that they require service autowiring, which was introduced in that branch.
NOTE: it will be usefull only for new version of the module which will support Drupal from 10.1
Issue fork commerce_variation_cart_form-3566959
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 #3
miroslavstankov commentedComment #5
miroslavstankov commentedComment #6
vitaliyb98 commentedComment #7
vitaliyb98 commented1. Got this error during testing:
Seems like plugin.manager.filter could be autowired only in this way:
2. We don't need to duplicate code in the legacy hook and OOP hook, in legacy hook we can use:
Comment #8
vitaliyb98 commentedMade fixes according to the comment Commnet
This changes should be tested with Drupal 10 and Drupal 11
Comment #9
johnpitcairn commentedThis will need to merge in the changes from #3212847: Error: Call to a member function bundle() on null in commerce_variation_cart.
Comment #10
vitaliyb98 commentedMade changes according to the comment #9
Comment #11
vitaliyb98 commentedTested with Drupal 10.1 and Drupal 11.3.6. LGTM
I also introduced a new 2.0.x branch, which supports Drupal 10.1 and newer.
Comment #12
vitaliyb98 commentedphpstan (previous major) has failed because #Legacy Hook and #Hook attribute.
There are two ways to deal with it:
- skip this into phpstan.neon
- allow failure for this job
I used the second one
Comment #14
vitaliyb98 commentedMerged into new 2.0.x branch, which will be used for the next major release