HookEvent class

HookEvent is a type provided to hook functions with information about the event.

// Example
$wire->addHookAfter('Pages::saved', function(HookEvent $event) {
  $page = $event->arguments(0);
  $event->message("You saved page $page->path");
}); 

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the HookEvent class also inherits all the methods and properties of: WireData and Wire.

Show $var?             Show args?        

Common

NameReturnSummary 
$event->arguments()
array null mixedRetrieve or set a hooked function argument
Can also be used as property: $event->arguments
 
$event->argumentsByName()
mixed arrayReturns an array of all arguments indexed by name, or the value of a single specified argument 
$event->cancelHooks bool When true, all remaining hooks will be cancelled, making this HookEvent the last one (be careful with this). 
$event->id string A unique identifier string that may be used with a call to `Wire::removeHook()`. 
$event->method string The name of the method that was called to generate the Hook event.  
$event->object Wire WireData WireArray Module Instance of the object where the Hook event originated.  
$event->options array An optional array of user-specified data that gets sent to the hooked function. The hook handling method may access it from $event->data. Also includes all the default hook properties.  
$event->removeHook($hookId)
HookEvent WireDataRemove a hook by ID 
$event->replace bool Set to boolean true in a 'before' hook if you want to prevent execution of the original hooked function. In such a case, your hook is replacing the function entirely. Not recommended, so be careful with this. 
$event->return mixed Applicable only for 'after' or ('replace' + 'before' hooks), contains the value returned by the above mentioned method. The hook handling method may modify this return value.  
$event->when string In an active hook, contains either the string 'before' or 'after', indicating whether it is executing before or after the hooked method.  

Additional methods and properties

In addition to the methods and properties above, HookEvent also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019
  • We added WebP image support this year and many have been adopting it in existing projects. We look at a process used for migrating existing websites to WebP images— from preliminary considerations to implementation & testing, w/lots of tips & tricks too: More
    16 August 2019
  • Core version 3.0.137 on the dev branch adds the ability to hook multiple methods at once, in a single call. This post details how it works and provides a useful example of how you might put it to use in your development environment— More
    2 August 2019

Latest news

  • ProcessWire Weekly #279
    This week in the 279th issue of ProcessWire Weekly we're going to introduce some of the latest third party modules out there, and highlight a brand new site of the week. Read on!
    Weekly.pw / 14 September 2019
  • ProcessWire 3.0.140 and FormBuilder v40
    This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140.
    Blog / 6 September 2019
  • Subscribe to weekly ProcessWire news

I just love the easy and intuitive ProcessWire API. ProcessWire rocks!” —Jens Martsch, Web developer