Skip to content

Commit 203ba0c

Browse files
authored
[6.0] Fix language auto-loading without Application in CMSPlugin (joomla#45993)
* Fix language autoloading without application * phpstan * test * test * typo
1 parent 2642ceb commit 203ba0c

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

libraries/src/Plugin/CMSPlugin.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ public function __construct($config = [])
187187
}
188188

189189
// Load the language files if needed.
190-
// It is required Application to be set, so we trying it here and in CMSPlugin::setApplication()
191-
if ($this->autoloadLanguage && $this->getApplication()) {
190+
if ($this->autoloadLanguage) {
192191
$this->autoloadLanguage();
193192
}
194193
}
@@ -253,6 +252,16 @@ final protected function autoloadLanguage(): void
253252

254253
$app = $this->getApplication();
255254

255+
// Try to get Application from Factory
256+
if (!$app) {
257+
try {
258+
$app = Factory::getApplication();
259+
} catch (\Exception) {
260+
// Cannot help here
261+
return;
262+
}
263+
}
264+
256265
// Check whether language already initialised in the Application, otherwise wait for it
257266
if (!$app->getLanguage()) {
258267
$app->getDispatcher()->addListener('onAfterInitialise', function () {
@@ -483,11 +492,6 @@ public function setApplication(CMSApplicationInterface $application): void
483492
if ($application->getLanguage()) {
484493
$this->setLanguage($application->getLanguage());
485494
}
486-
487-
// Try to load the language files if it were not loaded in the constructor already.
488-
if ($this->autoloadLanguage) {
489-
$this->autoloadLanguage();
490-
}
491495
}
492496

493497
/**

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13676,6 +13676,16 @@ parameters:
1367613676
count: 1
1367713677
path: libraries/src/Plugin/CMSPlugin.php
1367813678

13679+
-
13680+
message: '''
13681+
#^Call to method getDispatcher\(\) of deprecated interface Joomla\\CMS\\Application\\EventAwareInterface\:
13682+
4\.3 will be removed in 7\.0
13683+
This interface will be removed without replacement as the Joomla 3\.x compatibility layer will be removed$#
13684+
'''
13685+
identifier: method.deprecatedInterface
13686+
count: 1
13687+
path: libraries/src/Plugin/CMSPlugin.php
13688+
1367913689
-
1368013690
message: '''
1368113691
#^Call to deprecated method getCache\(\) of class Joomla\\CMS\\Factory\:

0 commit comments

Comments
 (0)