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

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.

  • Now it works, but I need the language filter plugin enable. How can I fix? – user2802368 Mar 15 '15 at 14:50
  • which joomla version you are using? – Nick Mar 15 '15 at 14:51
  • Joomla version 3.4.0 – user2802368 Mar 15 '15 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 Mar 15 '15 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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