7

Is there anyway to override MVC classes in Joomla 3?

I have found this thread but it is for Joomla 2.5. How to override core classes?

I have done MVC overrides in Joomla 2.5 successfully but now I have moved to Joomla 3. But that plugin not supported for Joomla 3.

I have found this article but I haven't good idea to write a plugin. Same concept has been used in the plugin which I used earlier in Joomla 2.5.

http://docs.joomla.org/How_to_override_the_component_mvc_from_the_Joomla!_core

And also can I extend those classes and overwrite methods?

Actually I want to override registration email template, user login task to check user type and profile view to retrieve more data from my tables.

I tried this plugin- https://github.com/phproberto/joomla-mvc-override But it gives errors.

    Warning: fopen(D:\xampp\htdocs\my_project/libraries/legacy/module/helper.php): failed to open stream: No such file or directory in D:\xampp\htdocs\my_project\libraries\joomla\filesystem\file.php on line 327
?>

    Fatal error: Class 'JModuleHelperLibraryDefault' not found in D:\xampp\htdocs\my_project\plugins\system\mvcoverride\core\module\helper.php on line 13

Is there anyone who faced this kind experience?

Thanks

3

Funny, I just finished yesterday the implementation of this plugin in a site.

A fellow webdev and I modified it for joomla 3.x and it works.

It's here : https://github.com/ghazal/plg_mvcoverride

It throws an error though when coupled with a nonumber.nl extension, Advanced Module Manager:

Call to undefined method JModuleHelper::addIncludePath()

Being in a hurry, my very unelegant solution was to comment out the first function :

    public function onAfterInitialise()
    {

    $moduleHelperContent = JFile::read(JPATH_LIBRARIES.'/cms/module/helper.php');
    $moduleHelperContent = str_replace('JModuleHelper', 'JModuleHelperLibraryDefault', $moduleHelperContent);
    $moduleHelperContent = str_replace('<?php','',$moduleHelperContent);
    eval($moduleHelperContent);
    jimport('joomla.application.module.helper');
    JLoader::register('jmodulehelper', dirname(__FILE__).'/module/helper.php', true);

}

and then, these 2 lines :

JModuleHelper::addIncludePath(JPATH_BASE.'/code/modules');
JModuleHelper::addIncludePath(JPATH_THEMES.'/'.$template.'/code/modules');

thus eliminating the possibility, in this case, to use it to override helper.php in a module.

I was about to post here to ask for help but you beat me to it.

  • Wow.. It works fine.. Thank you so much ghazal. I used a plugin before(Joomla 2.5) that you have mentioned in the document . Can you please update document? It would be helpful for others also. And also Can you add this in joomla extension directory please? – cha Nov 28 '14 at 11:00
  • Done in github as you asked. As for JED, it will take longer ... – ghazal Nov 28 '14 at 11:39
  • 1
    Finally, Alex (Chartier) found a working solution for the error that I thought was related to Advanced Module Manager. The original code was missing a line from the function it was overriding in jModuleHelper. Alex also corrected the $path issue. It's all been corrected in the github plugin. – ghazal Nov 30 '14 at 11:39

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.