Problem/Motivation

I have a custom module that depends on this module, and when I run the functional tests for my module I get this warning:

google_api_client_requirements without a #[LegacyRequirementsHook] attribute is deprecated in drupal:11.3.0 and removed in drupal:13.0.0. See https://www.drupal.org/node/3549685

Steps to reproduce

Test a module the depends on this one.

Proposed resolution

I was going to create an MR, but https://www.drupal.org/node/3492429 is problematic. It suggests creating a class (like GoogleAPIClientRequirements) in the Install\Requirements namespace that would return what google_api_client_requirements is returning.

The problem is because that page says "The code must not use any other code from the module as it loaded prior to the module being installed", and that's exactly what google_api_client_requirements does: it calls the google_api_client_load_library function in the module file.

So, one alternative is to just copy and paste google_api_client_load_library as a method in the new GoogleAPIClientRequirements class. That duplication wouldn't be great. Another alternative would be to put that function in a new class and load it from all places where it's used. However, since the module might not be enabled that means GoogleAPIClientRequirements would need to load the new class using require_once instead of it being autoloaded.

Remaining tasks

Figure out how to handle this in a maintainable and preferably elegant way. Or, just have duplicate code and include a note in both places. If the code of google_api_client_load_library needs to change, then it can just be copied and pasted.

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

tolstoydotcom created an issue. See original summary.

tolstoydotcom’s picture

Another aspect is using \Drupal calls in the GoogleAPIClientRequirements class: that will probably result in PHPStan warnings. However, since core modules make such calls I assume there's an exception somewhere.

nicxvan’s picture

If you put it in the install requirements class and it's static the Drupal service call won't trigger a phpstan warning.

Then you can call it statically from the update requirements hook if you want to.

Or you can just duplicate it and use dependency injection in the update requirements hook.

nicxvan’s picture

If you're looking to just match the current function then you should look at https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Extension...

since the current implementation only runs during the runtime phase.

tolstoydotcom’s picture

Assigned: Unassigned » tolstoydotcom

I'm putting the google_api_client_load_library function in a service, I'll create an MR soon.

tolstoydotcom’s picture

Status: Active » Needs review

tolstoydotcom’s picture

I keep running into merge conflicts, I'll try again next week.

elaman’s picture

Status: Needs review » Active

The module still has Drupal 8 and Drupal 9 and PHP 5.4 in its compatibility list. Trying to make it fully Drupal 11 and PHP 8 compatible, naturally breaks it.
I suggest closing this issue, since its having issues with MRs, then opening a new issue for Drupal 11 and Drupal 12 compatibility. There we can discuss and plan to drop Drupal 8 to 10 and support 11 and 12. It will have to be a major release 5.x branch.

tolstoydotcom’s picture

It does work with my changes on both D11 and D10, but I haven't tested other versions or with anything other than PHP 8.3.

I started this and I'll post updated code in a couple days: https://www.drupal.org/project/google_api_client/issues/3611819

In the meantime I'll close this.

tolstoydotcom’s picture

Status: Active » Closed (outdated)

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.