User

MarkRS/misc/override the core

From Joomla! Documentation

< User:MarkRS‎ | misc
Revision as of 11:02, 7 July 2016 by MarkRS (talk | contribs) (Override core functionality without making a mess, or a problem later on.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Override core functions, without hacking[edit]

Joomla 3.5

Audience[edit]

If you need to change something that requires coding, but you're not a hotshot PHP programmer, I hope you'll find this useful.

Why Change the Core[edit]

The Joomla core offers some fabulous functionality that can be used for lots of situations. Sometimes those situations don't exactly fit the way the core goes about things, but they're so close that it would be a cryin' shame, and a real waste of valuable time, to write the whole thing again, even if that's just copying what's already there.

It would be oh so nice to be able to make slight changes that gave the website a really polished, made to measure, feel when in fact you're really using the features available out of the box, almost.

Say you wanted to use the contacts component supplied, just slightly differently. If you just want to make the output look a little different, then that's no problem. The output override system will let you do that easily. But if you also want to add, say, the filtering functionality that's available in the back end for the contacts then you've got a different job. Yes, you can add those filter boxes the output, but without changes to the model they won't do anything.

General Overview[edit]

Change the model? Without hacking the core? Yes, don't hack the core code! It'll all end in tears. There is a plugin that you can use to do this, MVC override. That's a nice piece of work, the problem is it's not being updated. It also creates some problems in some situations that are hard to get around.

Fortunately for us, the expert beginner, it's not hard to create our own plugin that makes it easy for us to do it ourselves.

Strategy[edit]

We use a strategy that has been built into the Joomla core. The core always checks for framework classes in memory before it loads them from code. So all we have to do is ensure that our own copy of specific classes are loaded before Joomla would load them itself! of the correct names.

Joomla's plugin system is perfect for what we want. You simply need to find a trigger point late enough in the execution chain to have the facilities you're modifying available, and not so late that the classes you want to modify have already been loaded in their original form.

Let's do it[edit]

Situation[edit]

Let's take the situation mentioned above. You want to use the contacts component to show details for people in a certain category. Furthermore, let's say that the list is going to be very large and you want to offer your user search and filter facilities, the good ones that you the administrator can see in the back end, not the laughable search box offered in the standard front end.

Requirement[edit]

You're going to need to override the output template and use a new (although easy to copy from the back end) filter form, which means you need to override the view class (since the current front end one doesn't use a form), and override the model, to make use of the nifty filters you're bringing in. Here we go!

Output Template[edit]

This is the bit you're most likely to be familiar with. The very fine page about this will, I trust, be enough for you. In addition, look in the corresponding administration template to see how to include

View[edit]

Model[edit]

Field?[edit]