J3.x

OnContentPrepare called with JCategoryNode

From Joomla! Documentation

Executing a category blog view the event function onContentPrepare of content plugins: public function onContentPrepare($context, &$article, &$params, $limitstart)

is now called more than once per each article included in the category blog and it receives a quite unexpected JCategoryNode object as $article reference.

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


Errors reported

If your content plugin does not validate properly the $context of the caller it may generate PHP strict notices, for example if it work with the $article->catid property. Indeed the JCategoryNode object has not a catid property like the stdClass object referring to the real object that represents the article. If the plugin validates the context in a generic way such as the following this won't be enough anymore: preg_match('/com_content/i', $context);

Versions affected

General Information

This pertains only to Joomla! version(s): 3.7.0

What is the cause

This happens because of the new feature of custom fields introduced in Joomla 3.7


How to fix

Carefully validate the context of the plugin call, for example:

if($context == 'com_content.categories') { return; }

or

if(!$article instanceof stdClass) { return; }


Update content plugins accordingly.