?
avatar ahamed
ahamed
7 Oct 2020

Problem identified

I have a system plugin. Previously in 3.x the plugin initiated in the onAfterRoute event. In this event, the plugin attaches scripts/styles to the document and finally render the HtmlDocument like

$doc->render(false, ['template' => 'mytemplate', 'file' => 'component.php'])

Now for converting to the J4 beta I need to register and use styles/scripts using WebAssetManager. But attaching assets at the onAfterRoute event says-

Call to a member function getWebAssetManager() on null

And also in some events says that the "WebAssetManager is locked, you came late" something like this.
So my question is, at plugins where to Register and Use WebAssets and where not to.

Note: I don't want any template-specific assets i.e. any assets from atum or cassiopeia. I just need my own assets and own HTML to render after hitting a specific route.

Proposed solution

Open questions

Votes

# of Users Experiencing Issue
1/1
Average Importance Score
5.00

avatar ahamed ahamed - open - 7 Oct 2020
avatar joomla-cms-bot joomla-cms-bot - change - 7 Oct 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 7 Oct 2020
avatar ahamed ahamed - change - 7 Oct 2020
The description was changed
avatar ahamed ahamed - edited - 7 Oct 2020
avatar Fedik
Fedik - comment - 7 Oct 2020

You doing something hacky.

Call to a member function getWebAssetManager() on null

And that the result.

In normal runtime the asset can be registered between onAfterRoute and onBeforeCompileHead.
But preferable between onAfterDispatch and onBeforeRender

avatar ahamed
ahamed - comment - 7 Oct 2020

In normal runtime the asset can be registered between onAfterRoute and onBeforeCompileHead.
But preferable between onAfterDispatch and onBeforeRender

I've registered the assets at the onAfterDispatch event. But cannot use this

$doc->render(false, []);

method instead I've used

$doc->setBuffer($content, 'component');

And for rendering the the component.php file instead of the index.php file I've just set the input tmpl=component at the onAfterRoute event like-

Factory::getApplication()->input->set('tmpl', 'component');

And now it's working.

avatar Fedik
Fedik - comment - 7 Oct 2020

I suspect you have override joomla Document and some other classes, that why it not worked.

Please close the issue if it fixed.

avatar ahamed ahamed - change - 7 Oct 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-10-07 10:12:35
Closed_By ahamed
avatar ahamed ahamed - close - 7 Oct 2020

Add a Comment

Login with GitHub to post a comment