diff --git a/CHANGELOG-v3.md b/CHANGELOG-v3.md index 15965b979ba..717722783f4 100644 --- a/CHANGELOG-v3.md +++ b/CHANGELOG-v3.md @@ -4,6 +4,7 @@ ### Changed - Edit User pages will now warn editors when leaving the page with unsaved changes. ([#2832](https://github.com/craftcms/cms/issues/2832)) +- Modules are once again loaded before plugins, so they have a chance to register Twig initialization events before a plugin initializes Twig. ([#2831](https://github.com/craftcms/cms/issues/2831)) ### Fixed - Fixed an error that could occur in the Plugin Store. diff --git a/src/base/ApplicationTrait.php b/src/base/ApplicationTrait.php index 730542f97be..830d9844894 100644 --- a/src/base/ApplicationTrait.php +++ b/src/base/ApplicationTrait.php @@ -1108,9 +1108,9 @@ public function getVolumes() // ========================================================================= /** - * Initializes the application component + * Initializes things that should happen before the main Application::init() */ - private function _init() + private function _preInit() { $this->getLog(); @@ -1119,7 +1119,13 @@ private function _init() // Set the language $this->updateTargetLanguage(); + } + /** + * Initializes things that should happen after the main Application::init() + */ + private function _postInit() + { // Load the plugins $this->getPlugins()->loadPlugins(); diff --git a/src/console/Application.php b/src/console/Application.php index 447ccd7506a..c73dd768515 100644 --- a/src/console/Application.php +++ b/src/console/Application.php @@ -54,10 +54,9 @@ public function __construct($config = []) public function init() { $this->state = self::STATE_INIT; - // Important that we call $this->_init() before parent::init(), so that it's run before bootstrap() - // in case bootstrap() ends up loading a module that loads Twig, configuring Twig with the wrong timezone - $this->_init(); + $this->_preInit(); parent::init(); + $this->_postInit(); } /** diff --git a/src/web/Application.php b/src/web/Application.php index e7b51d6ffdc..d6c0cc6f8ad 100644 --- a/src/web/Application.php +++ b/src/web/Application.php @@ -94,12 +94,14 @@ public function __construct(array $config = []) public function init() { $this->state = self::STATE_INIT; - // Important that we call $this->_init() before parent::init(), so that it's run before bootstrap() - // in case bootstrap() ends up loading a module that loads Twig, configuring Twig with the wrong timezone - $this->_init(); + $this->_preInit(); parent::init(); + + // Initialize web application-specific stuff $this->ensureResourcePathExists(); $this->debugBootstrap(); + + $this->_postInit(); } /**