Louis and I have been working over the comments branch and looking at
how plugins interact with forms and data and things, and in that
process we feel it's time to rationalise most of the key events that
will form part of 1.6 (and leave some alone that aren't perfect but
aren't particularly broken).
As we all know plugins are loaded by group and this will not change.
What we are proposing, however, is to namespace the events and this
was discussed at the developer summit last year (at my place). The
namespaces are:
Config - reserved for a future purpose
Content - dealing with content CRUD
Extension - used by the installation process
User - anything to do with users
Following this methodology, and event affecting a user would prefix
with "onUser*" even though it might reside in it's own folder
(authentication or user, etc). All content events would prefix with
"onContent" and so on.
So let's go through a few examples.
USER
======
In the User namespace we would rename the following events:
onAuthenticate -> onUserAuthenticate
onAfterDeleteUser -> onUserAfterDelete
onAfterStoreUser -> onUserAfterDelete
onAfterStoreUsergroup -> onUserAfterSaveGroup
onBeforeDeleteUser -> onUserBeforeDelete
onBeforeStoreUser -> onUserBeforeSave
onLoginFailure -> onUserLoginFailure
onLoginUser -> onUserLogin
onLogoutFailure -> onUserLogoutFailure
onLogoutUser -> onUserLogout
In addition, there are some new events that will be introduced:
onUserAfterDeleteGroup
onUserBeforeDeleteGroup
onUserBeforeSaveGroup
EXTENSION
===========
In the Extension namespace we have all new events and we'd rename these to be:
onExtensionBeforeInstall
onExtensionAfterInstall
onExtensionBeforeUpdate
onExtensionAfterUpdate
onExtensionBeforeUninstall
onExtensionAfterUninstall
CONTENT
=========
In the Content namespace, we would rename the following events:
onAfterContentSave -> onContentAfterSave
onAfterDisplayContent -> onContentAfterDisplay
onAfterDisplayTitle -> onContentAfterTitle
onBeforeContentSave -> onContentBeforeSave
onBeforeDisplayContent -> onContentBeforeDisplay
onPrepareContent -> onContentPrepare
Now, one of the problems we have is that the existing plugins assume
you are dealing with an article only, and this is really not going to
be flexible enough to deal with all the new toys in 1.6 (including
some of the events I will mention soon). With the above-mentioned
content plugins we are going to need to add a context argument so that
the plugin knows what kind of content it will be dealing with. For
example, the onAfterContentSave is declared as:
// 1.5 format
function onAfterContentSave(&$article, $isNew)
we would change this to:
// 1.6 format
function onContentAfterSave($context, $data, $isNew)
in practice this would become:
$dispatcher->trigger('onContentAfterSave', 'com_banners.banner',
$banner, $isNew)
$dispatcher->trigger('onContentAfterSave', 'com_banners.client',
$client, $isNew)
$dispatcher->trigger('onContentAfterSave', 'com_content.article',
$article, $isNew)
$dispatcher->trigger('onContentAfterSave', 'com_weblink.weblink',
$weblink, $isNew)
In this way we can consistently intercept all content and the plugin
can pick and choose what it wants to work on.
With the new JForm API we can introduce the following generic events:
onContentPrepareForm
This is an event that allows a plugin to add additional XML data to
the form. This could be user profile fields, custom fields in an
article, etc.
onContentPrepareFormData
This is an event that compliments onPrepareForm but for the data. If
you have extra fields injected in a form, this method injects the
extra data that was saved if it has come from a custom source (note,
you don't need this if you are extending params fields as this is
handled just with onPrepareForm).
onContentPrepareCustomData
This is an event that collects custom data when displaying an object
(as opposed to using a form). This would allow you to display custom
user profile information, custom fields in an article, etc.
onContentBeforeDelete
onContentAfterDelete
A pair of events to trap the when content gets deleted.
onContentBeforeDelete can potentially stop some content from being
deleted.
onContentChangeState
This event would be fired, for example, when you publish or unpublish
a list of articles or other content.
Each of these events will include some sort of context to help the
plugin work out what kind of data it is working with.
---
We won't be touching the search or editor plugins for now - let the
sleeping dogs lie. The other system events (onAfterRoute, etc) will
also remain unchanged.
What are the implications?
Well, we are between a rock and a hard place. We could keep the
current names, but have to include a new event name for each type of
content (eg, onNewsfeedAfterSave, onBannerClientBeforeDelete) and that
could get onerous. We could keep the current names but risk existing
plugins breaking a site because we passed a weblink object to it and
it though it was an article. We could have a split
old-naming-convention and new-naming-convention. We could rationalise
and be consistent across the board providing maximum flexibility but
requiring developers to upgrade their plugin events.
In the end, we feel rationalisation is the best approach, and given
that plugin developers MUST change their XML install files anyway,
it's not an onerous task to map old names to new names. During this
process we will of course document the events (finally) so that you
can reference what they are supposed to do.
We are under a bit of time pressure so I would appreciate feedback on
this as quickly as possible. Jump into the #joomla-dev IRC if you see
Louis or I there to chat about it if you want. Also, if you want
additional triggers SPEAK NOW otherwise you will miss the boat for
their inclusion in 1.6 (and being prepared to code a patch would be
appreciated).
Thanks for your due consideration of this matter. Unfortunately there
is no easy road to take regarding the plugins, it's a matter of
choosing where we want to compromise.
Regards,
Andrew Eddie
http://www.theartofjoomla.com - the art of becoming a Joomla developer
--
You received this message because you are subscribed to the Google Groups "Joomla! CMS Development" group.
To post to this group, send an email to
joomla-...@googlegroups.com.
To unsubscribe from this group, send email to
joomla-dev-cm...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/joomla-dev-cms?hl=en-GB.