Skip to content

Commit d209806

Browse files
Fedikrichard67softforge
authored
[6.0] Restore onBeforeExecute event for CMSApplication (#45426)
* Restore onBeforeExecute for CMS application * Restore onBeforeExecute for CMS application --------- Co-authored-by: Richard Fath <[email protected]> Co-authored-by: Phil Walton <[email protected]>
1 parent 3ecac63 commit d209806

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

libraries/src/Application/CMSApplication.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Joomla\CMS\Event\Application\AfterRenderEvent;
1818
use Joomla\CMS\Event\Application\AfterRespondEvent;
1919
use Joomla\CMS\Event\Application\AfterRouteEvent;
20+
use Joomla\CMS\Event\Application\BeforeExecuteEvent;
2021
use Joomla\CMS\Event\Application\BeforeRenderEvent;
2122
use Joomla\CMS\Event\Application\BeforeRespondEvent;
2223
use Joomla\CMS\Event\ErrorEvent;
@@ -300,6 +301,16 @@ public function execute()
300301
$this->setupLogging();
301302
$this->createExtensionNamespaceMap();
302303

304+
// Trigger the onBeforeExecute event
305+
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
306+
$this->dispatchEvent(
307+
'onBeforeExecute',
308+
new BeforeExecuteEvent('onBeforeExecute', ['subject' => $this, 'container' => $this->getContainer()])
309+
);
310+
311+
// Mark beforeExecute in the profiler.
312+
JDEBUG ? $this->profiler->mark('beforeExecute event dispatched') : null;
313+
303314
// Perform application routines.
304315
$this->doExecute();
305316

@@ -809,7 +820,6 @@ protected function initialiseApp($options = [])
809820
PluginHelper::importPlugin('behaviour', null, true, $this->getDispatcher());
810821

811822
// Trigger the onAfterInitialise event.
812-
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
813823
$this->dispatchEvent(
814824
'onAfterInitialise',
815825
new AfterInitialiseEvent('onAfterInitialise', ['subject' => $this])

libraries/src/Application/SiteApplication.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,6 @@ protected function initialiseApp($options = [])
570570
$user->groups = [$guestUsergroup];
571571
}
572572

573-
if ($plugin = PluginHelper::getPlugin('system', 'languagefilter')) {
574-
$pluginParams = new Registry($plugin->params);
575-
$this->setLanguageFilter(true);
576-
$this->setDetectBrowser($pluginParams->get('detect_browser', 1) == 1);
577-
}
578-
579573
if (empty($options['language'])) {
580574
// Detect the specified language
581575
$lang = $this->input->getString('language', null);

plugins/system/languagefilter/src/Extension/LanguageFilter.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Joomla\CMS\Event\Application\AfterDispatchEvent;
1818
use Joomla\CMS\Event\Application\AfterInitialiseEvent;
1919
use Joomla\CMS\Event\Application\AfterRouteEvent;
20+
use Joomla\CMS\Event\Application\BeforeExecuteEvent;
2021
use Joomla\CMS\Event\Privacy\CollectCapabilitiesEvent;
2122
use Joomla\CMS\Event\User\AfterSaveEvent;
2223
use Joomla\CMS\Event\User\BeforeSaveEvent;
@@ -186,6 +187,7 @@ public static function getSubscribedEvents(): array
186187
* might be needed by other plugins
187188
*/
188189
return [
190+
'onBeforeExecute' => 'onBeforeExecute',
189191
'onAfterInitialise' => 'onAfterInitialise',
190192
'onAfterDispatch' => 'onAfterDispatch',
191193
'onAfterRoute' => 'onAfterRoute',
@@ -196,6 +198,28 @@ public static function getSubscribedEvents(): array
196198
];
197199
}
198200

201+
/**
202+
* Listener for the onBeforeExecute event
203+
*
204+
* @param BeforeExecuteEvent $event The Event object
205+
*
206+
* @return void
207+
*
208+
* @since __DEPLOY_VERSION__
209+
*/
210+
public function onBeforeExecute(BeforeExecuteEvent $event): void
211+
{
212+
$app = $event->getApplication();
213+
214+
if (!$app->isClient('site')) {
215+
return;
216+
}
217+
218+
// If a language was specified it has priority, otherwise use user or default language settings
219+
$app->setLanguageFilter(true);
220+
$app->setDetectBrowser($this->params->get('detect_browser', '1') == '1');
221+
}
222+
199223
/**
200224
* After initialise.
201225
*

0 commit comments

Comments
 (0)