Hooks
Hooks can be set anywhere in modules or template code using a simple syntax. They can be either before or after a event/method happening in PW. There's also way to using addHook to add a new property or method to an existing template variable.
All methods in PW that have a ___ prefix can be hooked on either before or after.
Hook in Modules:
$this->addHookBefore('ClassName::method', $this, 'yourLocalMethod');
$this->addHookAfter('ClassName::method', $this, 'yourLocalMethod');
Hook in Templates:
$object->addHookBefore('method', null, 'yourLocalMethod');
$object->addHookAfter('method', null, 'yourLocalMethod');
Where $object can be either a template variable like $page, $pages, $fields, $templates etc. Or an instance of a module you load before with $modules->get("ModuleName");
HookEvent
Instances of HookEvent are passed to Hook handlers when their requested method has been called.
public function yourLocalMethod(HookEvent $event){
$output = $event->return;
}
Useful Links
- Prioritising Hooks for same event
- Using hooks to alter default behavior of ProcessWire (article by teppo)
- Simple hooks tutorial: turn a PageArray into a list of links (tutorial by ryan)
About this
This list is generated from the latest dev branch of ProcessWire master branch.