1

I'm trying to override a class JMenuSite in libraries/cms/menu/site.php. I created a plugin system jmenusite.php

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

class plgSystemJmenusite extends JPlugin{

    public function  onAfterRoute () {
        require_once(JPATH_SITE.'/plugins/system/jmenusite/site.php');
    }
}
?>

I copied the files site.php in the folder of the plugin.

Joomla performs the original class and then gives me error:

 Fatal error: Cannot redeclare class JMenuSite

How can I override the existing class?

1 Answer 1

1

onAfterRoute event is not the one which will work for your scenario. As JMenuSite class gets loaded before this event is triggered.

You need to use onAfterInitialise event to achieve this.

Important note : With Joomla 3.4 there are some changes in the core code due to which it will not be possible to override this class in case language filter plugin is enabled. As Joomla intentionally loads this plugin to apply some language specific handling and this plugin will load JMenuSite class before any event is triggered.

4
  • Now it works, but I need the language filter plugin enable. How can I fix? Commented Mar 15, 2015 at 14:50
  • which joomla version you are using?
    – Nick
    Commented Mar 15, 2015 at 14:51
  • Joomla version 3.4.0 Commented Mar 15, 2015 at 14:59
  • well, i have already mentioned that with joomla 3.4 it will not be possible unless joomla adds some other way to achieve this or some patch needs to be added in the core code which is obviously not a good option
    – Nick
    Commented Mar 15, 2015 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.