User tests: Successful: Unsuccessful:
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.
Try to change smth via onAfterDisplay event.
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.
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.
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
| Category | ⇒ | Libraries |
| Status | New | ⇒ | Pending |
| Labels |
Added:
PR-4.3-dev
|
||
| Category | Libraries | ⇒ | Unit Tests Repository Administration com_admin SQL |
| Category | Unit Tests Repository Administration com_admin SQL | ⇒ | Libraries |
| Title |
|
||||||
| Labels |
Added:
Feature
PR-5.0-dev
|
||
| Status | Pending | ⇒ | Closed |
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2023-09-23 20:24:04 |
| Closed_By | ⇒ | HLeithner |
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.