Wire::addHookAfter()
Add a hook to be executed after the hooked method
- Use an "after" hook when you have code that should execute after a hookable method executes.
- One benefit of using an "after" hook is that you can have it modify the return value.
Example
// Attach hook to a method in current object
$this->addHookAfter('Page::path', $this, 'yourHookMethodName');
// Attach hook to an inline function
$this->addHookAfter('Page::path', function($event) { ... });
// Attach hook to a procedural function
$this->addHookAfter('Page::path', 'your_function_name');
// Attach hook from single object instance ($page) to inline function
$page->addHookAfter('path', function($event) { ... });Usage
// basic usage
$string = $wire->addHookAfter($method, $toObject);
// usage with all arguments
$string = $wire->addHookAfter($method, $toObject, $toMethod = null, array $options = []);Arguments
| Name | Type(s) | Description |
|---|---|---|
$method | string array | Method to hook in one of the following formats (please omit 3 leading underscores):
|
$toObject | object null callable | Specify one of the following:
|
$toMethod (optional) | string array | Method from $toObject, or function name to call on a hook event. This argument can be sustituted as the 2nd argument when the 2nd argument isn't needed, or it can be the $options argument. |
$options (optional) | array | Array of options that can modify behavior:
|
Return value
stringA special Hook ID (or CSV string of hook IDs) that should be retained if you need to remove the hook later.
API reference based on ProcessWire core version 3.0.252