Drupal 11.1 Crash

Created on 17 December 2024, 20 days ago

Hi,

I tried updating my site to 11.1 and there was an issue with the module file making calls early. Attached is a patch that should hopefully fix things.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @mattbloomfield
  • Sorry, should have posted this along with it. This was the error I was getting when trying to visit the site or use drush:

    In Drupal.php line 169:

    \Drupal::$container is not initialized yet. \Drupal::setContainer() must be
    called with a real container.

  • 🇳🇱Netherlands johnv

    How about this test upfront:

    diff --git a/office_hours.module b/office_hours.module
    index f3b535e..59bc7ff 100644
    --- a/office_hours.module
    +++ b/office_hours.module
    @@ -9,12 +9,15 @@ use Drupal\Core\Form\FormStateInterface;
     use Drupal\Core\Routing\RouteMatchInterface;
     use Drupal\office_hours\Plugin\Field\FieldType\OfficeHoursItemBase;
     
    +// Include file, avoiding container error during upgrade.
    +if (\Drupal::hasContainer()) {
     // Add theme.api.php hooks.
     \Drupal::moduleHandler()->loadInclude('office_hours', 'inc', 'office_hours.theme');
     // Add ExceptionItem field formatter theming/preprocessing.
     \Drupal::moduleHandler()->loadInclude('office_hours', 'inc', 'office_hours.theme.exceptions');
     // Add views hooks.
     \Drupal::moduleHandler()->loadInclude('office_hours', 'inc', 'office_hours.views');
    +}
     
     /**
      * Implements hook_help().
  • Sure, you're a maintainer so you'd know the code much better than I would. I just hope I helped in some small way.

  • 🇳🇱Netherlands johnv

    Indeed, but I am not in the process of updating, so perhaps you chan check in the next run.

  • 🇳🇱Netherlands johnv
    • johnv committed 74b55780 on 8.x-1.x
      Issue #3494659 by mattbloomfield: Error \Drupal::$container is not...
  • 🇳🇱Netherlands johnv

    Thanks. fixed in my above proposed way.

  • 🇨🇳China 司南

    hook implements in these inc files will be ignored, if \Drupal::hasContainer() return false when the .module file is load by drupal core.

  • 🇨🇳China 司南

    The correct way is to combin these inc file into .module files.

  • 🇳🇱Netherlands johnv

    Indeed, that is exactly the purpose. The files are not needed during upgrade. They will be loaded upon the next run, do they not?

    Do you have a coding suggestion?

  • 🇳🇱Netherlands johnv

    Putting this on Fixed, until it is reported that the committed solution does not solve the problem.

Production build 0.71.5 2024