Register plugin multiple groups

277 views
Skip to first unread message

Allon Moritz

unread,
Dec 18, 2012, 1:44:57 PM12/18/12
to joomla-de...@googlegroups.com
Hello
Is it possible to register a plugin for multiple groups? I try to avoid to create multiple plugins which do almost the same for different groups.

Olivier Nolbert

unread,
Dec 19, 2012, 3:57:46 AM12/19/12
to joomla-de...@googlegroups.com
Hi Allon,

Could you detail what your plugin does exactly ?

Sorry but I don't understand what you want to achieve...

Olivier


2012/12/18 Allon Moritz <allon....@gmail.com>
Hello
Is it possible to register a plugin for multiple groups? I try to avoid to create multiple plugins which do almost the same for different groups.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.



--
Olivier Nolbert, Jiliko
14 passage Lecroisey 76600 Le Havre, France
SIREN : 517 564 365


Marco Dings

unread,
Dec 19, 2012, 4:36:10 AM12/19/12
to joomla-de...@googlegroups.com
Groups as in ?
<extension version="2.5" type="plugin" group="community" method="upgrade">

Do you intend to register to your plugin class with say system AND community?

I did not think that possible but would like to be proven wrong..

Olivier Nolbert

unread,
Dec 19, 2012, 4:39:09 AM12/19/12
to joomla-de...@googlegroups.com
I think Marco got it...

What you could do is creating the plugins you need for the different groups and use commun functions implemented in a library.

Olivier


2012/12/19 Marco Dings <ma...@dings.net>

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/joomla-dev-general/-/67m0Wy39YL0J.

To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-gene...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

Allon Moritz

unread,
Dec 19, 2012, 4:59:08 AM12/19/12
to joomla-de...@googlegroups.com
Yes something like 
<extension version="2.5" type="plugin" groups="community,user,system" method="upgrade">

I know it sounds like a kind of strange question. But I need to do some synchronization with an external system. There I need to sync users and categories and permissions. This means I need to create for users, content, etc. a plugin. The customer is forced to install multiple plugins which are sync plugins for the same system. I want to avoid this. That's why I'm asking first before making for every group a single plugin.

Michael Babker

unread,
Dec 19, 2012, 6:42:33 AM12/19/12
to joomla-de...@googlegroups.com
I don't think you can do that, but you can have plugins extend one another.  So, you could have plgSystemMyplugin extends plgUserMyplugin instead of extending JPlugin.  Or, as suggested, use a common library for the plugins.  If you look at the Finder plugins, they all extend FinderIndexerAdapter which is a common interface for all of the methods in Smart Search.

Marco Dings

unread,
Dec 19, 2012, 8:15:04 AM12/19/12
to joomla-de...@googlegroups.com
The "problem" is in the registration/triggering.. because they are in different groups
* register to multiple groups by installer.. Don't think that is a practical option because the plugins for each group by default lives in it's own directory under plugins. Probably to do with autoloading etc?
* install to one group using installer and have the contructor register in the other groups.. Here i am out of my depth. Son't know if this is possible at all,


2012/12/19 Marco Dings <ma...@dings.net>
To unsubscribe from this group, send email to joomla-dev-general+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.
--
Olivier Nolbert, Jiliko
14 passage Lecroisey 76600 Le Havre, France
SIREN : 517 564 365


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-general+unsub...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/joomla-dev-general?hl=en-GB.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To post to this group, send an email to joomla-de...@googlegroups.com.
To unsubscribe from this group, send email to joomla-dev-general+unsub...@googlegroups.com.

Gary Mort

unread,
Dec 19, 2012, 12:59:16 PM12/19/12
to joomla-de...@googlegroups.com


On Tuesday, December 18, 2012 1:44:57 PM UTC-5, laoneo wrote:
Hello
Is it possible to register a plugin for multiple groups? I try to avoid to create multiple plugins which do almost the same for different groups.

It is possible to register a plugin for events in different groups - which I think is what you really want.

A plugin is a collection of event names, onAfterInitialize, onUserSave, onBeforeSaveContent, etc
These events have do not have any correlation with the plugin group.

A plugin group is a label used by Joomla to tell it if/when to register a set of plugin events.

The dispatcher which runs the plugin event methods does not care if they came from the system group, the content group, the editor group, or any other group.  When asked to run all plugins associated with onBeforeSaveContent it will just go and run them.

Now, with that said, there are 2 things to keep in mind:
It is the DISPATCHER object which actually calls the functions.  
The default dispatcher for the CMS is triggered via JApplication::triggerEvent()

NOT EVERY Plugin Group is used by the default dispatcher.  And even for plugin groups which are used by it, not every group is loaded for every page.

Joomla's authentication plugins, for example, are loaded by a different dispatcher.  So if you place an authentication event into a system plugin - it will not be triggered.  And if you place a system event into an authentication plugin it is not triggered.

The Content Plugins are in the default dispatcher, so you CAN define a content event in a system plugin and it will be used.   The Content Plugins are also conditional, they are only loaded if the page being displayed is from the content component or contains a content item.   And they are only loaded at that time.  
So if you define onBeforeRender in a content plugin, it will only be called if content is displayed[useful if, for example, your site displays content items using multiple modules, sometimes causes duplicate items to be displayed, and you want the LAST one in the list to be kept and the others deleted - you could have an onBedoreRender event which filters out the earlier ones....and since it was in the content group it will only be enabled if the page has content items!]

Timing issue warning
A Content Plugin which defines onAfterRoute is a useless thing.  While the event will be registered, Content Plugins don't generally get loaded until AFTER this event has been run. 

Clear as mud?

Gary Mort

unread,
Dec 19, 2012, 1:09:59 PM12/19/12
to joomla-de...@googlegroups.com
Another thing you can do is create your own plugin grouping.

So you would have, for example, a User Plugin, a System Plugin, and a Content Plugin
lanoneoUserSync, lanoneosSystemSync, lanoneoContentSync,
Give these plugins nice informative descriptions like:
This plugin will syncronize changes to the user for the website to the external site.  Please see the lanoneoSync group for further options - this plugin may only be on or off. 
For each of the events you are interested in, your code would be something like:
JPluginHelper::importPlugin('laoneoSync');
$this->triggerEvent('syncExternalData');
 
Then you can create one or more plugins in the laoneoSync group:
lanoneoSyncGoogleApps
  "This plugin will syncronize changes to user information to this websites Google Apps Account"
lanoneoSyncUbuntuOne
  "This plugin will syncronize changes to files on the system to Ubuntu One"
lanoneoSyncAmazonCDN
  "This plugin will synchronize changes to webpages via content or user updates and place them on the websites Amazon CDN server"

You can even combine the two methods, make a single systemPlugin[since that group is loaded 99% of the time] which loads and calls your own sync plugins so you can enable and disable individual external synchronization options via the plugin interface.

Sam Moffatt

unread,
Dec 19, 2012, 1:26:32 PM12/19/12
to joomla-de...@googlegroups.com
Both the user and system plugins will use the same dispatcher and while I'm not sure what community is and who uses it, however if they use the default dispatcher then a system plugin will likely have their events propagated to it.

Give it a go as a mega system plugin and see if it works.

Cheers,

Allon Moritz

unread,
Dec 20, 2012, 1:50:38 AM12/20/12
to joomla-de...@googlegroups.com

If I understood you right, making a system plugin and if I need to listen for none system events I can attach the plugin during onInitialize to some other events on the dispatcher? Can be a solution...what do you think about this?

Sam Moffatt

unread,
Dec 23, 2012, 5:35:29 PM12/23/12
to joomla-de...@googlegroups.com
Gary's posts on this topic should be clear that it doesn't matter what the group is for the dispatcher, it's just a mechanism for controlling which plugins are loaded at a certain time. Once a plugin is loaded, it'll get all events sent to the same dispatcher.

Cheers,
Reply all
Reply to author
Forward
0 new messages