Replace DrupalKernel::loadLegacyIncludes with composer autoload.files

Created on 21 April 2025, about 14 hours ago

Problem/Motivation

The DrupalKernel has a lot of responsibilities. One of which is loading some legacy function files which are in the process of being replaced. However, the kernel shouldn't be loading files as that's what the Composer autoloader is for.

Steps to reproduce

Proposed resolution

Move the files to core's composer.json under autoload.files. Remove them from loadLegacyIncludes and deprecate that method.

Files autoload rules are included whenever vendor/autoload.php is included, right after the autoloader is registered. The order of inclusion depends on package dependencies so that if package A depends on B, files in package B will be included first to ensure package B is fully initialized and ready to be used when files from package A are included.

This ensures the files are always loaded. The function is currently called in preHandle which is both manually called in tests and the KernelPreHandle middleware, so the end result of when functions are available is the same.

All code contained in the files are functions and thus the inclusion of the files do nothing on their own besides making the functions callable. There's no side-effects to including them. The files contain use statement, but used classes are not autoloaded until runtime code actually uses the class in an executed statement.

Remaining tasks

User interface changes

Introduced terminology

API changes

  • DrupalKernelInterface::loadLegacyIncludes is deprecated and scheduled for removal in 12.0
  • DrupalKernel::loadLegacyIncludes is deprecated and scheduled for removal in 12.0

Data model changes

Release notes snippet

DrupalKernelInterface::loadLegacyIncludes has been deprecated and scheduled for removal in 12.0, there is no replacement. The files it included will now be loaded by the Composer autoloader when vendor/autoload.php is first included.

DrupalKernel::preHandle no longer calls DrupalKernel::loadLegacyIncludes. If you relied on this behaviour to load your own include files, move them to the Composer autoloader instead.

πŸ“Œ Task
Status

Active

Version

11.1 πŸ”₯

Component

bootstrap system

Created by

πŸ‡³πŸ‡±Netherlands kingdutch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @kingdutch
  • Pipeline finished with Failed
    about 14 hours ago
    Total: 181s
    #478388
  • Pipeline finished with Failed
    about 13 hours ago
    Total: 148s
    #478403
  • Pipeline finished with Success
    about 10 hours ago
    Total: 412s
    #478520
  • πŸ‡«πŸ‡·France andypost

    Needs deprecation test and looks RTBC

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Also probably needs a CR and links updated.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Will this affect unit tests?
    If I understand correctly the legacy files would not be loaded before this change, but after this change all unit tests will load all legacy includes.

    Not sure if this is a problem or acceptable, but it likely is a change.

  • πŸ‡³πŸ‡±Netherlands kingdutch

    Will this affect unit tests?
    If I understand correctly the legacy files would not be loaded before this change, but after this change all unit tests will load all legacy includes.

    Not sure if this is a problem or acceptable, but it likely is a change.

    You understand correctly. There were two tests that still relied on those functions and redefined them themselves, those have been changed in the diff. For the other tests if they ignore the functions then nothing happens. I guess the only risk is that people start using them in more places? However, there's nothing stopping someone from doing that in a place that's covered by a test that's not a unit test, so I'd argue that's acceptable.

    I'll write up a change record and update the deprecation links later this week :) I'm not sure how I would go about writing a deprecation test. Any pointers to an example would be welcome.

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies β†’ .

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Left one other question.

    You don't need to test deprecations directly unless there is complex BC logic.

    The question is what happens if someone is calling that function directly and the files get loaded in composer as well.

  • πŸ‡¨πŸ‡¦Canada Charlie ChX Negyesi 🍁Canada

    My worry about unit tests would be performance but I am so often wrong in what is useless micro optimization and what is legit worry.

  • πŸ‡ΊπŸ‡ΈUnited States nicxvan

    Great question!

    This is somewhat anecdotal, the test run here was 6 minutes.

    I checked 4 other issues they all ranged from 8-15 minutes.

Production build 0.71.5 2024