EVENT-SUBSCRIBER-001
function onContentPrepare(...)
JPlugin onX methods vs SubscriberInterface
Method-name events still fire, but Joomla 4+ wants subscribers with typed Event objects. Native Joomla 6 quality means SubscriberInterface, not a JPlugin with onContentPrepare by convention.
function onContentPrepare(...) → CMSPlugin + SubscriberInterface::getSubscribedEvents()
Symptoms people search
plugin does not run on Joomla 6 · onContentPrepare never called
Replace this code
Swap function onContentPrepare(...) for CMSPlugin + SubscriberInterface::getSubscribedEvents().
Joomla 3
Remove or stop calling this
class PlgContentLms extends JPlugin {
public function onContentPrepare($context, &$article, &$params, $page = 0) {}
}Joomla 4 / 6
Use this instead
class Lms extends CMSPlugin implements SubscriberInterface {
public static function getSubscribedEvents(): array {
return ['onContentPrepare' => 'prepare'];
}
public function prepare(Event $event): void {}
}How to fix it
- 1Extend CMSPlugin and implement SubscriberInterface.
- 2Map event names in getSubscribedEvents().
- 3Read arguments from the Event object, not &$article by reference.
Also known as
SubscriberInterface · onContentPrepare · onAfterRender · JPlugin
There is no 1:1 swap for this one. The architecture changed. If you cannot rewrite it, Infyways can.
Related issues
- Joomla 3 → 4Joomla API
JError / JException
JError::raiseError() → throw new RuntimeException() / try-catch
- Joomla 3 → 4Events / plugins
JDispatcher / JEventDispatcher
JDispatcher::getInstance() → Event dispatcher + SubscriberInterface
- Joomla 3 → 4PHP
each() / create_function() / ereg / split
each($array) → foreach / closures / preg_*
- Joomla 3 → 4PHP
eval() in extensions
eval($code) → Never — forbidden for Infyways work
- Joomla 3 → 4Events / plugins
onAfterRender HTML string hacks
onAfterRender() { $body = JResponse::getBody(); } → Document events / WebAssetManager
- Joomla 5 → 6Events / plugins
Core plugin event names (J3 methods → subscribers)
onContentPrepare / onAfterDispatch / … → SubscriberInterface::getSubscribedEvents()