?
avatar regularlabs
regularlabs
19 May 2021

For an extension I have, I need to grab the article text from a certain article (different to the current article) and pas that through the content & system plugins via the onContentPrepare.:

JFactory::getApplication()->triggerEvent(
	'onContentPrepare',
	['com_content.article', &$article, &$article, 0]
);

I need to do this during the onAfterRender stage.
This works fine in Joomla 3.

However, in Joomla 4 this causes issues with the emailcloak plugin that tries to load assets: WebAssetManager->useAsset().

The resulting error is:

0 WebAssetManager is locked, you came late

So the question is:
Is this something that can be fixed? Or is there some other way that makes it possible to parse article objects through the plugins after the WebAssetManager gets locked without running into fatal errors?

image

avatar regularlabs regularlabs - open - 19 May 2021
avatar joomla-cms-bot joomla-cms-bot - change - 19 May 2021
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 19 May 2021
avatar regularlabs regularlabs - change - 19 May 2021
Title
[J4.0] Errors when triggering onContentPrepare on object on onAfterRender
[J4.0] Errors when triggering onContentPrepare on object in onAfterRender
avatar regularlabs regularlabs - edited - 19 May 2021
avatar Fedik
Fedik - comment - 19 May 2021

WebAssetManager is locked, you came late

This was made to prevent adding an assets after rendering. because the document is rendered and nothing can be added to it.
In past it was just ignored silently.

Last chance to do anything with assets is onBeforeCompileHead

I do not think that it is good idea to call onContentPrepare after render, there maybe more extensions, that may lead to weird things.

Maybe try another event like onBeforeRender, or maybe onAfterRenderModules (not sure here).

avatar regularlabs
regularlabs - comment - 19 May 2021

I think I can deal with my current hurdle by using the onAfterRenderModules instead.
It is a shame though that it is not possible to just parse a piece of text through the plugins at any stage, when you don't care about the scripts/styles...

avatar Fedik
Fedik - comment - 19 May 2021

It is a shame though that it is not possible to just parse a piece of text through the plugins at any stage

onContentPrepare meant to be run while dispatching of the component, this is by design.

avatar regularlabs regularlabs - change - 19 May 2021
Status New Closed
Closed_Date 0000-00-00 00:00:00 2021-05-19 18:29:12
Closed_By regularlabs
avatar regularlabs regularlabs - close - 19 May 2021
avatar regularlabs
regularlabs - comment - 19 May 2021

Well, actually when rendering articles (or object disguised as articles).
I know that. But plugins (and possibly other extensions) need to be able to pass content through the plugins (specifically the onContentPrepare) for whatever reason. Which the can, that's why Joomla uses the events system.
It is just that the decision to not ignore silently anymore takes away some flexibility that was there in Joomla 3.

But I'll work my way around it. No problem.

Add a Comment

Login with GitHub to post a comment