Problem/Motivation

In #3392616-5: Update to Symfony 6.4 we've found out that the Symfony\Component\DependencyInjection\ContainerAwareTrait and Symfony\Component\DependencyInjection\ContainerAwareInterface are being deprecated in Symfony 6.4 and removed in 7.0.

Proposed resolution

We can't get rid off all implementations and will need to fork those into core (#3392616-8: Update to Symfony 6.4 and #3392616-20: Update to Symfony 6.4)

However, we want to get rid of as many usage as possible, for that there is #3397519: [META] Reduce use of ContainerAware classes where possible.

MR!5181 is the actual MR, but since that also removes all the deprecation suppression it currently fails (hard...).

However if we put the MRs of the children of #3397519: [META] Reduce use of ContainerAware classes where possible on top of that MR, as done in MR!5182, we are fully green.

Remaining tasks

Postponed on #3397173: Convert both BookNavigationCacheContext and MenuActiveTrailsCacheContext to use lazy services
Review

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3397522

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

Spokje created an issue. See original summary.

spokje’s picture

Assigned: Unassigned » spokje
Issue summary: View changes
Status: Active » Needs work

Not quite sure what to do, the actual status would be PP-2, since this is waiting on the commit of both children of #3397519: [META] Reduce use of ContainerAware classes where possible to get rid of all the deprecation warnings.

But maybe someone wants to review the current state, so leave it on NW on my name for now.

quietone’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +Needs architectural review
Parent issue: #3392616: Update to Symfony 6.4 » #3394694: [Meta] Symfony 7 compatibility
Related issues: +#3392616: Update to Symfony 6.4

Adding what this is postponed on to the remaining tasks per Remining tasks.

Changing parent to the S7 compatibility issue, so we find all the related issues.

But maybe someone wants to review the current state, so leave it on NW on my name for now.

Hmm. This looks like a situation where the new tag "Needs architectural review" can help. Adding tag and setting to NR.

longwave’s picture

The event dispatcher just receives the entire container as an argument:

  event_dispatcher:
    class: Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher
    arguments: ['@service_container']

Can we just do this for the services that need it instead of copying the ContainerAware feature?

spokje’s picture

Assigned: spokje » Unassigned

Can we just do this for the services that need it instead of copying the ContainerAware feature?

Since I have no clue what this means, I'm quickly un-assigning myself so somebody else can pick this up.

longwave’s picture

It just means injecting the whole container as a service via a constructor argument, instead of using the ContainerAwareTrait/Interface helpers.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

spokje’s picture

Status: Needs work » Needs review

This is the best I could do. I think I've changed all non-factory services to use the container in their constructor and deprecated all the (previously inherited) setContainer methods.

spokje’s picture

Started working on some Factories, but I fear these will not work with constructors having a service container argument, since the container might not be ready yet?

It passes tests, but I would like some confirmation from somebody who actually knows what she/he is doing before continuing.

andypost’s picture

Issue summary: View changes
Issue tags: +Needs issue summary update

As I see in the MR5181 is the trait is removed but not replaced with fork, so summary needs update

Issue title said we gonna fork but MR doing replacement which is better to do as rector's rule to be reusable for contrib/custom code

IMO fixing just a namespace is preferable way, with follow-up to remove usage as the change very disruptive

smustgrave’s picture

Status: Needs review » Needs work

Believe #13 is enough for NW? If not feel free to put back.

claudiu.cristea’s picture

I've already hit this as in our project we're rejecting code triggering deprecations. It happened when some dependency updated Symfony from 6.3.5 to 6.4.1. Not sure whether to apply this patch or to pin Symfony

alexpott’s picture

StatusFileSize
new555 bytes

Here's a small patch to remove the deprecation from Symfony because you can't pin to 6.3.5 and use Drupal 10.2.1

alexpott’s picture

longwave’s picture

So it looks like in many of these cases we should be using service locators instead of injecting the entire container:

Sometimes, a service needs access to several other services without being sure that all of them will actually be used. In those cases, you may want the instantiation of the services to be lazy. However, that's not possible using the explicit dependency injection since services are not all meant to be lazy.

CacheFactory, CacheTagsInvalidator, CheckProvider, StreamWrapperManager, KernelDestructionSubscriber all look like they could use this technique.

EntityTypeManager and ClassResolver are more tricky and need access to the entire container, but I think we could just inject the container as a service in these cases.

longwave’s picture

Actually, KernelDestructionSubscriber can't use this because a service locator is a separate mini-container, and the destructor needs to know if each individual service was actually used in the main container.

longwave’s picture

Opened #3414625: Convert KernelDestructionSubscriber to use configurators for a slightly hacky way of dealing with KernelDestructionSubscriber.

longwave’s picture

Opened #3414627: Convert StreamWrapperManager to use a service locator to try out using a service locator in StreamWrapperManager.

longwave’s picture

longwave’s picture

Opened #3427741: Notify downstream users that ContainerAware is going away which would mean this can be closed as won't fix.

longwave’s picture

Status: Needs work » Closed (won't fix)

#3427741: Notify downstream users that ContainerAware is going away landed and we should be able to remove ContainerAware support entirely from Drupal 11 in #3431362: Remove support for ContainerAwareInterface.