ProcessWire is built around a modular architecture
Modules exist to enable a high level of extensibility and customization to an installation of ProcessWire. Modules are PHP files containing classes that adhere to ProcessWire's Module interface.
Installing a module is as simple as uploading the module's files to the /site/modules/ directory on your server and then clicking "install" in the Admin. Uninstalling is as simple as clicking "uninstall" in the module's settings, and then deleting it's directory from the server.
Modules may add hooks to methods/functions in ProcessWire's core, or to other modules. Nearly every component and action in ProcessWire is hookable. Much of ProcessWire itself is a collection of plugin modules. In fact, the ProcessWire admin application is just a group of modules, not actually part of ProcessWire's core.
Modules can schedule themselves to be executed before or after a given function/method in ProcessWire. They can manipulate the values provided to, or returned from, any method/function. Modules may also add new functions/methods to existing ProcessWire API objects. ProcessWire comes with a module interface for implementing any kind of plugin, as well as a few abstract and base objects for which predefined module types are defined.
Predefined modules
Examples of predefined module interfaces in ProcessWire include interfaces for field types (Fieldtype modules), form fields (Inputfield modules), admin processes (Process modules), text formatters (Textformatter modules), jQuery plugins (Jquery modules), and markup generation (Markup modules).
Naming conventions
When creating new modules that fall in this class of predefined types, naming conventions should be used to identify the module as being of that type. For instance, if you create a new Textformatter module called "Something" you should name it "TextformatterSomething". Likewise, a new Inputfield module called "SuperCheckbox" should be named "InputfieldSuperCheckbox". Naming conventions you would use at the beginning of the module class name are: Textformatter, Fieldtype, Inputfield, Process, Jquery, and Markup. For modules that aren't based on these existing types, you don't need to consider naming conventions.
Plugin modules can be designated to be bootstrapped with ProcessWire, or only loaded when requested by the API. Modules may also be specified as single or multiple instance.
Module example
Despite the technical sounding description, creating a module is very simple. ProcessWire includes a "Hello World" module that demonstrates the basics and includes a lot of commenting. Here is a simple example of a module that displays a message every time a page is saved:
class Example extends WireData implements Module {
public static function getModuleInfo() {
return array(
'title' => 'Example module',
'version' => 100,
'summary' => 'Display message when pages are saved',
'singular' => true,
'autoload' => true
);
}
public function init() {
$this->pages->addHookAfter('save', $this, 'exampleMethod');
}
public function exampleMethod($event) {
$page = $event->arguments[0];
$this->message("You just saved page: {$page->url}");
}
}
This is a basic example. For a fully commented example that does more, please see the /site/modules/Helloworld.module example with your ProcessWire installation.
Module-specific information
Post a Comment
All fields are required. Your e-mail is kept confidential and not included with your comment.