Module Handler logic in .module file breaks sites on D11.1

Created on 10 January 2025, 3 months ago

Problem/Motivation

All the define('SOMETHING', 'value') logic in the root of the .module file that calls \Drupal::moduleHandler() breaks sites in D11.

Steps to reproduce

Install the module on D11.1. The site stops working.

The website encountered an unexpected error. Try again later.
Drupal\Core\DependencyInjection\ContainerNotInitializedException: \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container. in Drupal::getContainer() (line 169 of core/lib/Drupal.php).

Drupal::getContainer() (Line: 543)
Drupal::moduleHandler() (Line: 54)
include_once() (Line: 184)
Drupal\Core\Hook\HookCollectorPass->collectModuleHookImplementations() (Line: 147)
Drupal\Core\Hook\HookCollectorPass::collectAllHookImplementations() (Line: 78)
Drupal\Core\Hook\HookCollectorPass->process() (Line: 73)
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() (Line: 814)
Symfony\Component\DependencyInjection\ContainerBuilder->compile() (Line: 1380)
Drupal\Core\DrupalKernel->compileContainer() (Line: 899)
Drupal\Core\DrupalKernel->initializeContainer() (Line: 505)
Drupal\Core\DrupalKernel->boot() (Line: 707)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Proposed resolution

Create utility class that has getters on it that does essentially the same thing.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

heddn Nicaragua

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

Merge Requests

Comments & Activities

  • Issue created by @heddn
  • Merge request !6Resolve #3498884 "Module handler logic" → (Merged) created by heddn
  • Pipeline finished with Failed
    3 months ago
    Total: 162s
    #392502
  • Pipeline finished with Success
    3 months ago
    Total: 205s
    #392517
  • 🇳🇴Norway hansfn

    Thanks a lot for the testing and patch, heddn. I obviously haven't had time to test the module on D11. I was planning to, but paid work ...

    It seems you have made very reasonable changes, but I would have preferred one PR for the Mime stuff and another for the Token stuff. Or does the token stuff also break the site? Looking at the issue, you are only pointing to the defines as breakers. Do you mind the extra work?

    So, some questions because I'm not following Drupal development closely:

    • How long has "type: mapping" in the schema been wrong ...
    • How long has "type: mapping" in the schema been wrong ...
    • Why do you create a ViewsSendMimeInterface? Is it a requirement? I don't expect there to be anymore implementations of that interface than the one you created?

    Again, I really appreciate that you help keeping this module a live. It really should be completely rewritten, but I guess it works well enough for some people as is. Well, not for people on D11. And maybe it was broken for 10.3 also. It seems I last tested with 10.1.5

  • heddn Nicaragua

    Replied in MR. Thanks for your kind review.

  • Pipeline finished with Skipped
    3 months ago
    #395220
  • 🇳🇴Norway hansfn

    Merging didn't seem to change status to fixed. Doing that now. Again - thanks heddn.

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

Production build 0.71.5 2024