Skip to content

Commit

Permalink
Document event, AfterInitialiseDocument Event
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed May 7, 2023
1 parent 34024c5 commit 1efc69a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
8 changes: 6 additions & 2 deletions 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 @@ -141,8 +142,11 @@ public function dispatch($component = null)
$document->setGenerator('Joomla! - Open Source Content Management');

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

$contents = ComponentHelper::renderComponent($component);
$document->setBuffer($contents, 'component');
Expand Down
8 changes: 6 additions & 2 deletions 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 @@ -416,8 +417,11 @@ public function dispatch($component = null)
Factory::$document = $document;

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

$contents = ComponentHelper::renderComponent($component);
$document->setBuffer($contents, 'component');
Expand Down
8 changes: 6 additions & 2 deletions 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 @@ -206,8 +207,11 @@ public function dispatch($component = null)
}

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

$contents = ComponentHelper::renderComponent($component);
$document->setBuffer($contents, 'component');
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

0 comments on commit 1efc69a

Please sign in to comment.