activeCollab 2 slightly changes the way modules are defined. Our goal was to use object oriented design for things that were procedural in the past. This way, we reduced number of files needed to define a module and amount of code that you need to write.
In previous versions, you needed 5 files to define a module:
Instead of all these files, now we have a single file - module class. Its name is based on module name. If module name is tickets, this class would be TicketsModule (defined in TicketsModule.class.php file) and if it is status_updates, name is StatusUpdatesModule (defined in StatusUpdatesModule.class.php file).
Information and operation handled by the old files are now fully covered with this class:
Router and EventManager now know which module they are loading so there is no need to specify module in route and handler definition any more. You can do that if you wish (to override other modules for example), but it’s optional.
Because new module definitions extend Module class, there are helper methods they inherit that make definition of new configuration options and email templates much easier. Please check addConfigOption() and addEmailTemplate() of Module class for details.
And finally, we added support for platform tests before module is installed. Before you can install a module, activeCollab calls its canBeInstalled() method. If it returns true, module can be installed, but if it returns false, system will abort the installation. Module developer can log messages to inform the user about the tests performed and/or reasons why the module can’t be installed.
Check this implementation from new Incoming Mail module:
/**
* Returns true if this module can be installed
*
* @param array $log
* @return boolean
*/
function canBeInstalled(&$log) {
if(extension_loaded('imap')) {
$log[] = lang('OK: IMAP extension loaded');
} else {
$log[] = lang('This module requires IMAP PHP extension to be installed. Read more about IMAP extension in PHP documentation: http://www.php.net/imap');
return false;
} // if
return true;
} // canBeInstalled
It’s that easy!
The best way to learn the new system is to see it working. Because of that we recommend that you download latest activeCollab 2 beta from your profile and check out IncomingMailModule or TicketsModule implementations to see all the new features implemented and working.
If you have something important to say about the issues discussed in this post please write at hi@a51dev.com.