Read the Framework Plugins guide to get the absolute most out of this tutorial. We build on concepts that are covered in that guide.
There are times when you may want to alter or augment the functionality of FILEman to suit a specific need. You might want to:
- send an email when a file is submitted
- create a simple log of FILEman events
Whatever you would like to do is possible with Plugins and our Event-driven architecture. Event listeners can be registered to almost any action in FILEman. More so, multiple listeners can be registered to a single event.
In most cases, you will want to register an event listener to a controller action. However, you can also register listeners to model and view actions.
There are a number of entities in FILEman whose MVC actions can have event listeners. Some examples are:
|Site component||Administrator component|
To get a sense of the granularity of the events that a plugin can subscribe to, have a look at “What is Possible?” in the Framework Plugins guide.
A plugin consists of at least 2 files: a PHP class and an XML descriptor.
Note: See Plugins Creation and Installation section in the Framework guide for more information.
In the following snippet, we have named our plugin
file. However, you are free to name your plugin anything you like.
group attribute specifies
fileman. The system will make sure that this group of plugins is loaded whenever a FILEman event is broadcast.
The example below might help with keeping track of file submissions:
This class sends an email to the admininstrator whenever someone submits a file using the Submit menu item in the frontend.
onAfterFilemanSubmitControllerAdd method follows a specific naming convention.
For controller-focused events, the
$event variable gets the
data property. This is made up of the input data of the request coming into the action. We intercept it with an After event handler in order to get information about the file after it is added.
Refer to MVC Actions and Events for a more detailed discussion about specific
$event variable properties and the actions they are geared towards.
Let’s take a look at a plugin for logging of FILEman events. This plugin will get information from the event and let you add the information to a custom database table.
Events to respond to:
- When: After - we do this after the action has run so that if the action were to fail, our event listener won’t run.
- Component: Fileman & Files - This is to only affect the FILEman and Files extensions.
- Name: Files - We’re only interested in files.
- Action: Add & Delete - Add/delete events.
The event method names we need for this example are:
We want to get the following information about this event: (1) What file was added? (2) Who added the file?
Note that we used
Files instead of
Fileman. This is because FILEman makes use of the built-in Joomlatools
com_files component especially for managing files and folders in the backend.
Our delete event will use both
onAfterFilemanFileControllerAdd event will be triggered when a user deletes a file from the frontend while
onAfterFilesFileControllerAdd will be triggered from the admin.
Normally, your methods would have different functions. But for this example, we will have one method call the other since they have the same function.
Let our developers personally assist you. You can ask development related questions in our Support Center. Only for Business or Agency subscribers.