?
avatar joeforjoomla
joeforjoomla
28 Feb 2017

Steps to reproduce the issue

Open a category bog view and inspect the event onContentPrepare function of content plugins:
public function onContentPrepare($context, &$article, &$params, $limitstart)

It's called more than once per each article included in the category blog and it receives an unexpected JCategoryNode object as $article reference

Expected result

Called once for each article included in the category blog view and receiving a stdClass object as $article parameter

Actual result

Called once for each article included in the category blog view but even for each category link showed in that view thus receiving a JCategoryNode object as $article parameter. This leads to errors when a content plugin deals for example with $article->catid that is not an available property in JCategoryNode

System information (as much as possible)

Additional comments

avatar joeforjoomla joeforjoomla - open - 28 Feb 2017
avatar joomla-cms-bot joomla-cms-bot - change - 28 Feb 2017
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Feb 2017
avatar Bakual
Bakual - comment - 1 Mar 2017

The added event call is for the category itself so it supports for example custom fields. That's not a bug.

The bug is actually in hte plugin which doesn't do proper checks.
It needs to check the passed context or presence of the catid property in ypur plugin and if it doesn't match just return.

avatar joeforjoomla
joeforjoomla - comment - 1 Mar 2017

Ok but at least it should be document to inform developers to add to all plugins:
if($context == 'com_content.categories') {
return;
}

avatar Bakual
Bakual - comment - 1 Mar 2017

That's nothing new.

Plugins should always at least either check for the context they want to fire from or check the presence of the needed properties. Many should also check for the document type (eg only run on HTML).

The same thing may happen when 3rd party extensions trigger those events.

avatar joeforjoomla
joeforjoomla - comment - 1 Mar 2017

I know. There is nothing new.
BUT i found a plugin checking the context as:
preg_match('/com_content/i', $context);
now failing because content.categories is still valid but getting a JCategoryNode.

avatar mbabker
mbabker - comment - 1 Mar 2017

Feel free to add something to https://docs.joomla.org/Category:Version_3.7.0_FAQ but I'm not seeing a bug in core.

avatar joeforjoomla
joeforjoomla - comment - 1 Mar 2017

Tried to add a FAQ but no success, i got blocked.

This action has been automatically identified as harmful, and it has been disallowed. In addition, as a security measure, some privileges routinely granted to established accounts have been temporarily revoked from your account. A brief description of the abuse rule which your action matched is: Stupid Tricks Check

avatar mbabker
mbabker - comment - 1 Mar 2017

@Hutchy68 I believe you're the smart guy when it comes to Mediawiki and our ACL.

avatar Bakual Bakual - change - 1 Mar 2017
Status New Closed
Closed_Date 0000-00-00 00:00:00 2017-03-01 14:41:17
Closed_By Bakual
avatar Bakual Bakual - close - 1 Mar 2017
avatar Bakual
Bakual - comment - 1 Mar 2017

I'm closing this issue as it is a bug in a 3rd party plugin.

avatar Hutchy68
Hutchy68 - comment - 2 Mar 2017

@joeforjoomla sorry about that must've been all the $ signs in your edit. ? I added you to the contributors group. You should be able to edit now w/ no problem.

avatar joeforjoomla
joeforjoomla - comment - 2 Mar 2017

Thank you very much @Hutchy68
I added it here: https://docs.joomla.org/J3.x:OnContentPrepare_called_with_JCategoryNode
Not sure if you need to approve it.

avatar Sandra97
Sandra97 - comment - 2 Mar 2017

IMHO, as it seems to be a bug with a 3rd party plugin, I don't think JDocs is the right place for this article as the bug seems to not be present in the Core. JDocs is not here to give fix for bugs in 3rd party extensions.

Add a Comment

Login with GitHub to post a comment