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

Command icon 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

vitaliyb98 created an issue. See original summary.

miroslavstankov made their first commit to this issue’s fork.

miroslavstankov’s picture

Assigned: Unassigned » miroslavstankov

miroslavstankov’s picture

Assigned: miroslavstankov » Unassigned
Status: Active » Needs review
vitaliyb98’s picture

Assigned: Unassigned » vitaliyb98
vitaliyb98’s picture

Status: Needs review » Needs work

1. Got this error during testing:

Cannot autowire service "Drupal\commerce_variation_cart_form\Hook\CommerceVariationCartFormHooks": argument "$filterManager" of method "__construct()" references class "Drupal\filter\FilterPluginManager" but no such service exists. You should maybe alias this class to the existing "plugin.manager.filter" service.

Seems like plugin.manager.filter could be autowired only in this way:

    #[Autowire(service: 'plugin.manager.filter')]
    private readonly FilterPluginManager $filterManager,

2. We don't need to duplicate code in the legacy hook and OOP hook, in legacy hook we can use:

function commerce_variation_cart_form_help($route_name, RouteMatchInterface $route_match) {
  return \Drupal::service('Drupal\commerce_variation_cart_form\Hook\CommerceVariationCartFormHooks')->help($route_name, $route_match);
}
vitaliyb98’s picture

Assigned: vitaliyb98 » Unassigned
Status: Needs work » Needs review

Made fixes according to the comment Commnet

This changes should be tested with Drupal 10 and Drupal 11

johnpitcairn’s picture

Status: Needs review » Needs work
vitaliyb98’s picture

Status: Needs work » Needs review

Made changes according to the comment #9

vitaliyb98’s picture

Status: Needs review » Reviewed & tested by the community

Tested 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.

vitaliyb98’s picture

Status: Reviewed & tested by the community » Fixed

phpstan (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

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

vitaliyb98’s picture

Merged into new 2.0.x branch, which will be used for the next major release

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.