Supplementary data
Event Listeners in Logger for Statamic have a supplement
method that accepts your event, and returns an array of data that gets merged with the listener's main data array.
Note: This is only needed when extending an existing listener. If you're creating your own new listener, there's no need to use the supplement
method: you'll need to define data
anyway.
In this example, we are extending the Entry listener.
Note that the data
method in the Entry listener already returns:
1[2 'id' => 1,3 'name' => 'Entry Name',4 'collection' => [5 'id' => 'pages',6 'name' => 'Pages'7 ],8 'site' => 'default'9]
We can write our supplement
method, extending the Entry listener, and let's say we want to get the Entry's content to be added to the log:
1class Entry extends \MityDigital\StatamicLogger\Listeners\Entry2{3 public function supplement(mixed $event): array4 {5 return [6 'content' => $event->entry->get('content', '')7 ];8 }9}
With this new supplement
method, the listeners logged data will be:
1[ 2 'id' => 1, 3 'name' => 'Entry Name', 4 'collection' => [ 5 'id' => 'pages', 6 'name' => 'Pages' 7 ], 8 'site' => 'default', 9 'content' => 'This is the content of the Entry'10]
Don't forget to subscribe to your new listener to take advantage of this.