Feature PR-4.3-dev PR-5.0-dev Pending

User tests: Successful: Unsuccessful:

avatar Denitz
Denitz
29 Aug 2023

Summary of Changes

Currently, the onAfterDisplay event via Joomla\CMS\Event\View\DisplayEvent doesn't allow to modify the view output, but it's logical that we should be able to modify the output.

The patch allows 3rd-party plugins to modify the view output by changing the source argument.

Testing Instructions

Try to change smth via onAfterDisplay event.

Actual result BEFORE applying this Pull Request

You can't modify the view output before it's optionally stored to view cache. You can only use onAfterDispatch event and modify the component document buffer but this event forces the execution of custom code even if the cached output is displayed and results into extra costs.

Expected result AFTER applying this Pull Request

You can easily modify the view output: add your handler into any system plugin which implements SubscriberInterface:

    public static function getSubscribedEvents(): array
    {
        return [
            ...
            'onAfterDisplay' => 'onAfterDisplay',
        ];
    }

    public function onAfterDisplay(\Joomla\CMS\Event\View\DisplayEvent $e)
    {
        $e->setArgument('source', '<h1>Hello from onAfterDisplay!</h1>' . $e->getArgument('source'));
    }

Now we can modify the view output and add custom scripts which will next be optionally cached in view cache.

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar joomla-cms-bot joomla-cms-bot - change - 29 Aug 2023
Category Libraries
avatar Denitz Denitz - open - 29 Aug 2023
avatar Denitz Denitz - change - 29 Aug 2023
Status New Pending
avatar Denitz Denitz - change - 29 Aug 2023
Labels Added: PR-4.3-dev
avatar joomla-cms-bot joomla-cms-bot - change - 22 Sep 2023
Category Libraries Unit Tests Repository Administration com_admin SQL
avatar joomla-cms-bot joomla-cms-bot - change - 22 Sep 2023
Category Unit Tests Repository Administration com_admin SQL Libraries
avatar Denitz Denitz - change - 22 Sep 2023
Title
Allow onAfterDisplay event to modify view output
[5.0] Allow onAfterDisplay event to modify view output
avatar Denitz Denitz - edited - 22 Sep 2023
avatar Denitz Denitz - change - 23 Sep 2023
Labels Added: Feature PR-5.0-dev
avatar HLeithner HLeithner - close - 23 Sep 2023
avatar HLeithner
HLeithner - comment - 23 Sep 2023

Several Maintainers are not happy with this, because we already have events to modify the document. So I'm closing this for now. thanks anyway for creating this pr.

avatar HLeithner HLeithner - change - 23 Sep 2023
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2023-09-23 20:24:04
Closed_By HLeithner

Add a Comment

Login with GitHub to post a comment