-
-
Notifications
You must be signed in to change notification settings - Fork 45
Introduction to Triggers
Triggers come in two flavours: calls and filters. If you invoke a trigger, you must provide a unique name for it so that modules can respond to it. If you want to respond to a trigger, you create a function in your module matching the name of the trigger. A list of the triggers in the codebase can be found in the file triggers_list.txt.
A call executes named functions at a certain point in the program flow, optionally with a set of arguments. The unique name is the only required argument; any additional arguments supplied to the call are passed on to the responders. Multiple names can be supplied as an array to a single invocation. When a call is invoked, active modules will be scanned for responder functions (or aliases) matching the unique name, and any responders discovered will be executed. A module is able to set the priority of each of its responders.
Here is an example of a call:
Trigger::current()->call("runtime");
The return value from the call is:
- A concatenated string if all calls return a string, or;
-
false
if none of the triggers exist, or; - the most substantial returned value decided by
oneof()
.
The goal of a filter is to modify a particular target and return the modification. The target for filtering is the first argument, and the unique name is the second argument; any additional arguments supplied to the filter are passed on to the responders. Multiple names can be supplied as an array to a single invocation. When a filter is invoked, active modules will be scanned for responder functions (or aliases) matching the unique name, and any responders discovered will be executed. A module is able to set the priority of each of its responders.
Here is an example of a filter:
Trigger::current()->filter($function, "send_mail");
The return value from the filter is the modified target.
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