-
-
Notifications
You must be signed in to change notification settings - Fork 45
Anatomy of a Module
Modules are the most powerful and general-purpose of the four types of extensions. Modules are structurally very simple – they simply extend the Modules
class with a class named after the file and its containing directory (using camelization rules), providing methods that correspond to trigger calls and filters.
class CamelizedFolderName extends Modules {
# Camelization accepts hyphens and underscores: foo-bar and foo_bar
public function this_is_a_callback($arg) {
# Do your thing
}
public function this_is_a_filter($target, $arg) {
# Do your thing to $target
return $target;
# You may also take $target by reference and not have to return it.
}
}
All of these functions are optional.
This function is called after all of the modules and feathers are instantiated. It exists because calling other triggers in your module's __construct()
function would be problematic because not every extension is ready to react.
This function is called when the module is enabled. Use this for setting up configuration settings, creating database tables, adding group permissions, etc.
This function is called when the module is disabled. There is one possible argument, and that's if your module has a confirm
metadata item; the argument will be a boolean of whether or not the user confirmed the dialogue.
In typical usage, __uninstall()
drops any database tables (if $confirm
is true
– but that's up to you), removes configuration settings, and removes group permissions that the module added.
There are a few functions that the Modules
class provides to modules, mainly to be used in the __construct()
or __init()
function.
This function is used for aliasing a Trigger to a different function name in your module:
function __init() {
$this->addAlias("markup_post_text", "foo_bar");
}
This function is used for setting a priority for a Trigger in your module. The default priority is 10; this default is set even if this function is not called.
A typical use of this function is ensuring your module's function is called before another. For example, a Foo module that supports external references (typically at the bottom of your post) might be truncated by a Bar Module. To prevent this from happening, simply set the priority of the filter function for the Foo module (typically "markup_text" or "markup_post_text") to a lower number value, such as 8, in order to assign a higher priority:
function __init() {
$this->setPriority("markup_post_text", 8);
}
This is the wiki for Chyrp Lite: An ultra-lightweight blogging engine, written in PHP.
- About Permissions
- Tour of a Theme
- Twig Reference
- Twig Variables
- Object Attributes
- Routes and Controllers
- Making Your First Module
- Debug and Tester Modes
- About Errors
- Introduction to Helpers
- Introduction to Translations
- Introduction to Triggers
- Anatomy of info.php Files
- Anatomy of a Feather
- Anatomy of a Module
- Anatomy of a Theme
- Anatomy of a Post
- Localizing Extensions
- Adding Ajax Functionality
- Working with JavaScript
- Working with Model
- Working with Config