Rafael Diaz-Tushman

Overriding the Logic in Core (or any!) Joomla Components

It is common knowledge within the Joomla Development Community that Joomla allows you to override the HTML output for any extension (including core ones) that use the Joomla MVC Framework. In itself,
that is pretty exciting because it means that you can make an extension look however you want even without changing its core files, which would otherwise be known as "hacking" the core files.


However, what if you wanted to override more than just the HTML output? For example, what if you wanted Joomla to fire a plugin event every time a module was edited? Or what if you wanted Joomla to fire a plugin event each time a content article was deleted? In short, what if you wanted to change bits of the LOGIC in core components as opposed to just the HTML output?


Since Joomla 1.5 was released, it has been possible to override the controllers and models in core components using a method posted on Joomla.org:


http://community.joomla.org/blogs/community/521-did-you-know-overri...


However, if you take a look at the comments on the blog post, you'll see that not many people have had success doing so (or at least they didn't publicly sing about it).


Well, in our Tienda project, we found there were certain parts of the core registration workflow that we wanted to change, but:

  1. we didn't want to hack com_user
  2. we didn't want to create a "registration" view within com_tienda

(Why didn't we want #2? Well, because a front-end user could bypass the com_tienda registration by changing the URL)


To resolve the issue, we added an entire clone of the com_user component to a system plugin -- not just the controller class -- and by doing so, have been able to completely alter the com_user registration workflow.


The best parts are:

  • This is a method you could replicate with any component in Joomla
  • No hacking of core files is involved
  • The ability to template override is still preserved

If you'd like to see what we've done and how we did it, register over at http://projects.dioscouri.com.
The system plugin will be part of the Tienda 0.3.1 release (expected in less than 10 days).


(This blog post originally was posted here: http://www.dioscouri.com/index.php?option=com_content&view=sect...)

Views: 421

Tags: component, core, ecommerce, joomla, override

Amy Stephen Comment by Amy Stephen on March 12, 2010 at 9:08am
Rafael - thanks for sharing this. I am buried right now, trying to finish a project. I am very interested in what you are talking about. I ran into the same challenge when I created a custom renderer.

Now, I plan to spend some time (WHEN I FIND IT!) studying your solution, but, I want to ask you, if you used an approach that actually does allow us to override the core class like the blog suggested, then, are you also planning to propose this (PLEASE) for 1.6?

Good to "see" you around. You must also be very busy! Thanks for the post and inviting us to review the code.
Rafael Diaz-Tushman Comment by Rafael Diaz-Tushman on March 12, 2010 at 9:37am
Oh, things are busier today then they have ever been for Dioscouri... and I'm not complaining at all :-)

@being able to find it -- you're right, i probably should outline in further detail here within the blog post exactly what we did. I'll write a follow-up.

@actually overriding the core class: unfortunately, our solution is merely a work-around. Because of the way the core component's entrypoint files are written (for example, com_user's "user.php" file) there is no way to properly/efficiently/intelligently override the core controller (and in some cases, the core component helper files). Our solution is essentially a trick to workaround this limitation.

@proposing to 1.6: i'll think on that, but the proper solution for 1.6 would be to rewrite the way they include/require core class files, and it isn't a small task. considering my current workload, its hard to pull myself away from it for volunteer core work (that often gets shot down without a critical thought), especially when there are others getting paid to do similar work for the core...
Ivo Apostolov Comment by Ivo Apostolov on March 12, 2010 at 10:10am
Same logic was applied in Protos SEF, Phoca Internationalization plugin and the Unicode Slugs plugin.
All of these overwrite the class related to automated creation of aliases.
Rafael Diaz-Tushman Comment by Rafael Diaz-Tushman on March 12, 2010 at 10:46am
Ivo, you're making my point for me. It would be GREAT if we could apply the same logic that is used to override JFilterOutput in those plugins.

Unfortunately, however, the com_user (or any core components) entrypoint files do not use JLoader::register() or JLoader::import() to load their controller files.

IF they used JLoader, then we could do a much simpler override, similar to what is done in those plugins with JFilterOutput.

Since they don't use JLoader, we had to do this workaround...
Ivo Apostolov Comment by Ivo Apostolov on March 12, 2010 at 2:22pm
I got it Rafael :)
Tienda looks very promising.
Ewout Wierda Comment by Ewout Wierda on March 13, 2010 at 1:25am
I don't have coding skills on the level you all have, but recently I was thinking that it would be nice if the use of every core component would be preceded by a plugin check that allows redirection to another component. So one would make a plugin for redirection, a replacement component, and then the core component being replaced can be switched off in the installer. Like that, I was thinking, there would be no need for double functionality and I hoped it might even encourage development. In this scenario, for example, I could use the Joomla core modules component or one of the components made by X, Y and Z, and I might choose Y because it has ways to overcome the menu assignment limitations.
Rafael Diaz-Tushman Comment by Rafael Diaz-Tushman on March 14, 2010 at 3:26pm
Amy Stephen Comment by Amy Stephen on March 14, 2010 at 3:48pm
Rafael - you are my hero! THANK YOU for hanging in there with them, over the past several months, and helping expose this architectural issue. Looks like Sam's lightbulb might have flickered on. Hopefully, this will be addressed in 1.6. I am very thankful to you for this - you are helping fix a real troubling problem.
Stian Didriksen Comment by Stian Didriksen on March 14, 2010 at 5:27pm
I agree with Amy here, great work Rafael!
Júlio Pontes Comment by Júlio Pontes on January 18, 2011 at 11:50am

Comment

You need to be a member of All Together, As A Whole to add comments!

Join All Together, As A Whole

Badge

Loading…

© 2012   Created by Amy Stephen.

Badges  |  Report an Issue  |  Terms of Service