Customer Site Data and Gates
The customer site away from the screen. 41 filters change data, 10 gates stop an action, and 30 hooks report an event.
Overview
Screen hooks add HTML. The hooks here touch the data deciding what a page shows, stop an action, or report what happened.
Telling the three apart decides where your work goes. Adding a row to a list is a filter. Stopping a spam comment is a gate. Telling an outside system is an event hook.
Reference
The ones that change data
The most used of the forty-one filters. Most hand the value over by reference, and the Ref column of an entry says which one you can change.
The ones that stop
Ten gates. They share one contract: returning a non-empty string stops the action, and that text reaches the customer as the error.
The ones that report
Most of the thirty event hooks report what the customer did on their account. Opening a key, writing a comment, sending a form.
addData().
The three contracts side by side
// A FILTER: add your own panel to the dashboard (by reference)
Hook::add('filter:client.dashboard.panels', 10, function (&$panels) {
$panels[] = ['title' => 'Acme', 'body' => AcmePanel::html()];
});
// A GATE: stop the comment where the spam score is high
Hook::add('gate:client.blog_comment', 10,
function ($owner_id, $parent_id, $message) {
if (Spam::score($message) > 80) return 'Your comment was not saved.';
return null;
});
// AN EVENT: write the opened key to the audit trail
Hook::add('action:client.api_key_created', 10, function ($owner_id, $new_id, $perms) {
Audit::keyOpened($owner_id, $new_id, $perms);
});
Pitfalls
Most customer hooks hand you the account id in the first parameter. Use it. Reading from the session brings the wrong person on sub-account and account-switch flows. On a call arriving through the API there is no session at all.
A gate runs on that flow alone. Where the same work can be done through the API, that path may not pass this gate. To hold a rule everywhere, check from the hook's entry which call paths the gate covers.
The filter touching a page's finished output runs on every page view. A heavy query or an outside call inside it is paid for by the whole site. Cache the heavy work and use only the ready answer in the listener.
Related Articles
Thanks for your feedback!
Our support team is here around the clock for anything you can't find above.