Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion libraries/src/Application/AdministratorApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Joomla\Application\Web\WebClient;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Application\AfterInitialiseDocumentEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Input\Input;
Expand Down Expand Up @@ -137,11 +138,17 @@ public function dispatch($component = null)
$document->setDescription($this->get('MetaDesc'));
$document->setGenerator('Joomla! - Open Source Content Management');

// Trigger the onAfterInitialiseDocument event.
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
$this->dispatchEvent(
'onAfterInitialiseDocument',
new AfterInitialiseDocumentEvent('onAfterInitialiseDocument', ['subject' => $this, 'document' => $document])
);

$contents = ComponentHelper::renderComponent($component);
$document->setBuffer($contents, ['type' => 'component']);

// Trigger the onAfterDispatch event.
PluginHelper::importPlugin('system');
$this->triggerEvent('onAfterDispatch');
}

Expand Down
8 changes: 7 additions & 1 deletion libraries/src/Application/ApiApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Joomla\Application\Web\WebClient;
use Joomla\CMS\Access\Exception\AuthenticationFailed;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Application\AfterInitialiseDocumentEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Router\ApiRouter;
Expand Down Expand Up @@ -412,11 +413,16 @@ public function dispatch($component = null)
// Set up the params
$document = Factory::getDocument();

// Trigger the onAfterInitialiseDocument event.
$this->dispatchEvent(
'onAfterInitialiseDocument',
new AfterInitialiseDocumentEvent('onAfterInitialiseDocument', ['subject' => $this, 'document' => $document])
);

$contents = ComponentHelper::renderComponent($component);
$document->setBuffer($contents, ['type' => 'component']);

// Trigger the onAfterDispatch event.
PluginHelper::importPlugin('system');
$this->triggerEvent('onAfterDispatch');
}
}
9 changes: 8 additions & 1 deletion libraries/src/Application/SiteApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Joomla\CMS\Cache\CacheControllerFactoryAwareTrait;
use Joomla\CMS\Cache\Controller\OutputController;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Event\Application\AfterInitialiseDocumentEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\InputFilter;
use Joomla\CMS\Input\Input;
Expand Down Expand Up @@ -205,11 +206,17 @@ public function dispatch($component = null)
$document->setGenerator('Joomla! - Open Source Content Management');
}

// Trigger the onAfterInitialiseDocument event.
PluginHelper::importPlugin('system', null, true, $this->getDispatcher());
$this->dispatchEvent(
'onAfterInitialiseDocument',
new AfterInitialiseDocumentEvent('onAfterInitialiseDocument', ['subject' => $this, 'document' => $document])
);

$contents = ComponentHelper::renderComponent($component);
$document->setBuffer($contents, ['type' => 'component']);

// Trigger the onAfterDispatch event.
PluginHelper::importPlugin('system');
$this->triggerEvent('onAfterDispatch');
}

Expand Down
23 changes: 23 additions & 0 deletions libraries/src/Event/Application/AfterInitialiseDocumentEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/**
* Joomla! Content Management System
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\CMS\Event\Application;

// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
* Event class for AfterInitialiseDocument event
*
* @since __DEPLOY_VERSION__
*/
class AfterInitialiseDocumentEvent extends ApplicationDocumentEvent
{
}
10 changes: 10 additions & 0 deletions libraries/src/Exception/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Error\AbstractRenderer;
use Joomla\CMS\Event\Application\AfterInitialiseDocumentEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;

Expand Down Expand Up @@ -118,6 +119,15 @@ public static function render(\Throwable $error)
Factory::$document = $renderer->getDocument();
Factory::getApplication()->loadDocument(Factory::$document);

// Trigger the onAfterInitialiseDocument event.
$app->getDispatcher()->dispatch(
'onAfterInitialiseDocument',
new AfterInitialiseDocumentEvent('onAfterInitialiseDocument', [
'subject' => $app,
'document' => $renderer->getDocument(),
])
);

$data = $renderer->render($error);

// If nothing was rendered, just use the message from the Exception
Expand Down