diff --git a/libraries/src/Plugin/CMSPlugin.php b/libraries/src/Plugin/CMSPlugin.php index c2c10854ad6fb..e489948acd55a 100644 --- a/libraries/src/Plugin/CMSPlugin.php +++ b/libraries/src/Plugin/CMSPlugin.php @@ -187,8 +187,7 @@ public function __construct($config = []) } // Load the language files if needed. - // It is required Application to be set, so we trying it here and in CMSPlugin::setApplication() - if ($this->autoloadLanguage && $this->getApplication()) { + if ($this->autoloadLanguage) { $this->autoloadLanguage(); } } @@ -253,6 +252,16 @@ final protected function autoloadLanguage(): void $app = $this->getApplication(); + // Try to get Application from Factory + if (!$app) { + try { + $app = Factory::getApplication(); + } catch (\Exception) { + // Cannot help here + return; + } + } + // Check whether language already initialised in the Application, otherwise wait for it if (!$app->getLanguage()) { $app->getDispatcher()->addListener('onAfterInitialise', function () { @@ -483,11 +492,6 @@ public function setApplication(CMSApplicationInterface $application): void if ($application->getLanguage()) { $this->setLanguage($application->getLanguage()); } - - // Try to load the language files if it were not loaded in the constructor already. - if ($this->autoloadLanguage) { - $this->autoloadLanguage(); - } } /** diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 97d4e2d7a68ec..7840bbd8a9d78 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -13676,6 +13676,16 @@ parameters: count: 1 path: libraries/src/Plugin/CMSPlugin.php + - + message: ''' + #^Call to method getDispatcher\(\) of deprecated interface Joomla\\CMS\\Application\\EventAwareInterface\: + 4\.3 will be removed in 7\.0 + This interface will be removed without replacement as the Joomla 3\.x compatibility layer will be removed$# + ''' + identifier: method.deprecatedInterface + count: 1 + path: libraries/src/Plugin/CMSPlugin.php + - message: ''' #^Call to deprecated method getCache\(\) of class Joomla\\CMS\\Factory\: