2

Is it possible - and is so what is the right way - to create a Joomla 3 plugin that ads new functionality to an existing module or component. I have made some minor but useful UI functionality changes to a popular component and module that I would share with others. I feel that editing the source is not the way, a plugin would be best. Thanks!

Yatko
  • 8,715
  • 9
  • 40
  • 46

2 Answers2

2

Yes, Its possible Joomla plugin is designed for that purpose,

You can add more features to existing component or module using Joomla plugin events.

There are many extensions that are using this concept like extending default users component com_users, com_virtuemart etc.

If you are using UI features I think System plugin will help you to solve the challenges

For an example I made a new feature to com_virtuemart with Product Zoom facility , It uses System Plugin events .

Hope it make sense..

Jobin
  • 8,238
  • 1
  • 33
  • 52
  • Can you extend component models, though? Your plug-in is not extending a model, it is using search-and-replace regex before the page is loaded. Likewise, system plugins hook onto events and not extend models (as far as I can see). It feels a slightly messy way of extending a component (though probably the only one). – RichardB Jul 04 '14 at 08:53
  • @RichardB its based on requirement , means you need to extend the models you can do that based on available hooks like payment,shipment etc. Mine is simple one Just altering the UI! – Jobin Jul 04 '14 at 09:10
  • Not sure how you'd override a component model via the available hooks, all of which seem to take place outside of the component being loaded. For example, say I wanted to override com_content's getItem function in ContentModelArticle so that instead of calling that function it ran an alternative one. As far as I can tell, you'd have to wait for that component to render and then fiddle with the output. Do you have any examples of a component's model being extended? I have never seen it done. – RichardB Jul 04 '14 at 09:23
  • @RichardB I didn't mean you can do such a thing, you can `extend` doesn't mean an `override`, The OP mentioned `UI functionality changes` so most can cover up with plugin even he needs to write a DB query,forms etc. – Jobin Jul 04 '14 at 09:34
  • 1
    @RichardB even some dirty tricks is there [like](http://stackoverflow.com/questions/13763539/overriding-joomla-core-component-file) – Jobin Jul 04 '14 at 09:39
  • 1
    I get you. Thought you meant there was a *proper* Joomla way to extend a component's class. That link is very interesting. I suspect it is not considered good practise to do that, but, yeah, would work. Thanks! – RichardB Jul 04 '14 at 09:44
  • Hi again, it seems Plugin Events are referring to articles and cannot find the proper solution to include code into an existing component, without actually adding some code into the component itself that calls the plugin or at least parts of it. Please show me an example. I am trying to add functionality to an existing gallery component using my own plugin, functionality that involves wrapping certain - existing - layout elements into a div. I would like to inject this code trough a plugin and not by editing the original component and add the
    around the code, I am about to handle.
    – Yatko Nov 25 '14 at 01:24
  • @Yatko [Download](http://www.walkswithme.net/related-products-slider-for-virtuemart) this plugin and check the code I do the same thing overwriting two divs with my own and adding few additional divs to acheive my goal – Jobin Nov 26 '14 at 13:39
  • Thank you @JobinJose we found a method in the meantime and now I will compare with your code to see if we did the right thing. Thanks a lot! – Yatko Nov 27 '14 at 18:13
  • Thank you @JobinJose Jose we found a method in the meantime and now I will compare with your code to see if we did the right thing. Thanks a lot! – Yatko Nov 27 '14 at 18:14
1

I'm pretty sure there is no "right way" to do this, as Joomla is designed to only allow you to overwrite the views rather than the models.

(If you don't know how to do that - copy the component view's default.php file into your template to templates/yourtemplate/html/com_componentname/viewname/default.php. )

However, someone has written this to allow you to over-ride models - http://extensions.joomla.org/extensions/style-a-design/templating/15611 . Downloading their code and looking into it would probably give you a hacky way of doing it.

Their use of eval suggests that it is going rather outside the Joomla framework, however.

A list of events you can hook a plug-in onto is here: http://docs.joomla.org/Plugin/Events - you can search-and-replace variables and output at any of those points, though that is not really "infiltrating the existing module or component", as it will happen outside of that component being loaded.

RichardB
  • 2,615
  • 1
  • 11
  • 14