Account and Contact Hooks
The eight hooks over the profile picture, addresses, linked providers and preferences.
Overview
Everything a customer uses to describe themselves lives here: the profile picture, billing addresses, linked social accounts and notification preferences.
The address side carries four hooks: the save gate and its event, the default changing, and deletion. The default address is the one printed on invoices.
Reference
Following a profile picture change
Runs when a customer uploads or removes a profile picture.
set uploaded, removed taken away.Hook::add('action:user.avatar_changed', 10, function ($uid, $action, $picture) {
// On the removal branch the path arrives EMPTY.
if ($action === 'removed') { Acme::dropAvatar($uid); return; }
Acme::mirrorAvatar($uid, $picture);
});Stopping a contact being saved
Runs before a customer saves a contact address.
Hook::add('gate:user.contact_save', 10, function ($uid, $data, $id) {
// A zero id means a new record.
if (!Acme::taxNumberValid($data)) return 'The tax details did not verify.';
return null;
});Following a contact being saved
Runs after a contact address is saved.
Hook::add('action:user.contact_saved', 10, function ($uid, $saved_id, $data, $is_new) {
Acme::syncContact($uid, $saved_id, $data);
});Following the default contact changing
Runs when an address becomes the default. The default is the address printed on invoices.
Hook::add('action:user.contact_default_changed', 10, function ($uid, $id) {
// The default address is the one printed on invoices.
Acme::syncBillingAddress($uid, $id);
});Following a contact being deleted
Runs after a contact address is deleted.
Hook::add('action:user.contact_deleted', 10, function ($uid, $id, $existing) {
Acme::dropContact($uid, $id);
});Following a social account being linked
Runs when an account is linked to an outside provider.
Hook::add('action:user.connected_provider', 10, function ($user, $mod_name) {
Acme::noteLink((int) ($user->id ?? 0), $mod_name);
});Following notification preferences changing
Runs when a customer changes which notifications they receive.
Hook::add('action:user.notification_preferences_changed', 10, function ($uid, $prefs) {
Acme::syncPreferences($uid, $prefs);
});Producing the text of an activity record
Runs while the visible text of an account activity is resolved. Produce the text for your own activity keys here.
Hook::add('filter:user.action_text', 10, function ($text, $ctx) {
// The hook runs only when no text was found.
if (!str_starts_with($ctx['key'] ?? '', 'acme.')) return null;
return Acme::actionText($ctx['key'], $ctx['lang'] ?? '', $ctx['variables'] ?? []);
});Pitfalls
The profile picture hook fires for uploads and removals alike, and on removal the path field always arrives empty. A listener using the path directly then works with nothing on that branch.
Changing the default is more than a preference: the invoices that follow carry that address. If you keep an accounting side in step, listen on this hook too.
Related Articles
Obrigado pela sua opinião!
A nossa equipa de apoio está disponível a qualquer hora para ajudar com o que não encontrar acima.