How to override core classes?



Sometimes there is a need to override core classes to get more functionality or to make some core functions work in another way. Is there any way how to override core classes? If it is possible then what issues I can face by overriding them?

Dmitry Rekun

Posted 2014-04-23T14:56:20.363

Reputation: 3 692

1It would be great if you could refine your question to make it a bit more specific or to describe a clear problem. – Valentin Despa – 2014-04-23T16:00:45.753



Yes it is possible.

You can use a system plugin to override the classes, please read this link and this and this

Two problems that you will face:

  1. you need to override the whole class (not just parts of it)

  2. if the core is updated and the class is also updated/changed, you need to update your override (if needed).


Posted 2014-04-23T14:56:20.363

Reputation: 650

3It would be useful if you could paste the pertinent steps from the links provided, or at least give a description of the links, in case they move or change. – codinghands – 2014-04-25T13:48:45.707


I created a plugin a while ago that allows you to override core classes, but it still falls prey to the problems that @jackJoe pointed out in his answer. However, it allows you to do the overrides cleanly.

Don Gilbert

Posted 2014-04-23T14:56:20.363

Reputation: 1 022

There is a substantial problem with your simple script, is that it doesn't preload components. So, if you override components, it really doesn't work for most of them (e.g. the com_content component). It works well, but it must preload component so that it can override them (you can't override something that hasn't been declared yet). Oh, and you must use onAfterRoute instead of doing the whole thing in the constructor. If you want to know what I mean by this comment then try overriding components/com_content/models/articles.php . – itoctopus – 2016-11-06T04:11:43.723

7Just want to say that this solution works beautifully, and that Don is a true kindred spirit of Open Source - hats off to him and his work!!! – GDP – 2014-06-18T15:58:02.677


I was on this one for very long time and promised Don that once I am done will give more details about it .

I needed to override Joomla MVC for components and tell Joomla to look for overrides in my plugin html folder also , not only inside template html folder.

What I never liked is when developers actually take Joomla default class and mess with it , so I rather extend that class if I can, instead of braking something.

My process does following.

  1. Get the class I need to override
  2. Read it, replace class name , create new file in my temp class folder
  3. Load my version of the class
  4. Load Joomla class
  5. Register my extend method which extends function loadTemplate to look for override in my plugin,than joomla template and last joomla component

here is the image rather

First parts in the snippet below is checking where the user is , if he is about to update Joomla I am deleting the temp class files that were created to make sure that we get fresh ones when the update is complete which than takes care of JackJoe number 2.

if (($this->Input('option') == 'com_joomlaupdate' && $this->Input('task') == 'update.install') || ($this->Input('option') == 'com_joomlaupdate' && $this->Input('layout') == 'complete')) {

    JFolder::delete(JPATH_SITE . '/plugins/system/yjsg/includes/yjsgcore/classes/extend/classes/');
    JFolder::create(JPATH_SITE . '/plugins/system/yjsg/includes/yjsgcore/classes/extend/classes/');
    $indexContent = '';
    JFile::write(JPATH_SITE . '/plugins/system/yjsg/includes/yjsgcore/classes/extend/classes/index.html', $indexContent);

$YjsgJViewDefaultRead         = JPATH_LIBRARIES . '/legacy/view/legacy.php';
$YjsgJViewDefaultFile         = YJSGEXTEND . "classes" . YJDS . "Yjsg" . $isView . "Default" . $IsJversion . ".php";

    //extend JView library class

    if (!JFile::exists($YjsgJViewDefaultFile)) {
        $YjsgJViewDefault = JFile::read($YjsgJViewDefaultRead);
        $YjsgJViewDefault = str_replace('class ' . $isView, 'class Yjsg' . $isView . 'Default', $YjsgJViewDefault);
        JFile::write($YjsgJViewDefaultFile, $YjsgJViewDefault);

    JLoader::register($isView, YJSGEXTEND . $IsJversion . '/component/view.php', true);


Posted 2014-04-23T14:56:20.363

Reputation: 594