PHP API, Hooks & CLI
For the complete class and method dictionary (ContactNormalizer, ContactDeduplicator, ContactMergeService, ContactPrivacyService, ContactRetentionService, ContactAddressService, ContactTransferService), read site/modules/Contacts/API.md or run php index.php docs get-text Contacts.
All 11 Hookable Methods (Contacts & ProcessContacts)
Section titled “All 11 Hookable Methods (Contacts & ProcessContacts)”| Hook | Arguments & Return | Timing | What It Does |
|---|---|---|---|
Contacts::resolveBlueprint |
(string $type, array $definition): array |
After | Customizes any contacts-* Entries blueprint schema before registration. |
Contacts::afterContactSaved |
(ContactEntry $contact, bool $isNew): void |
After | Fires after a single or batch contact save completes normalization. |
Contacts::afterOrganizationSaved |
(OrganizationEntry $organization, bool $isNew): void |
After | Fires after a single or batch organization save completes. |
Contacts::beforeMerge |
(string $scope, EntryItem $primary, EntryItem $duplicate, array $strategy): void |
Before | Validates or prepares downstream state right before an atomic merge. |
Contacts::afterMerge |
(string $scope, EntryItem $primary, string $duplicateId, array $stats): void |
After | Repoints foreign UUID references in downstream modules from $duplicateId to $primary->id. |
Contacts::collectSubjectData |
(EntryItem $contact, array $payload): array |
After | Appends module-specific personal data to GDPR subject export bundles. |
Contacts::collectTimelineItems |
(EntryItem $record, array $items = [], array $options = []): array |
After | Injects external activity events into Contacts/TimelineFeed and timelineFor(). |
Contacts::afterAnonymize |
(EntryItem $contact, string $reason): void |
After | Scrubs cached PII copies in downstream modules after GDPR erasure. |
Contacts::forwardWebhook |
(string $event, array $payload): void |
After | Forwards contacts.* lifecycle webhooks to Headless or custom sinks. |
Contacts::clearCache |
(): void |
After | Fires when request and WireCache directory caches are invalidated after mutations. |
ProcessContacts::translations |
(): array |
After | Returns localized UI strings for the Setup -> Contacts React workspace. |
Hook Examples (site/ready.php)
Section titled “Hook Examples (site/ready.php)”<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Contacts\Entity\ContactEntry;use Totoglu\Entries\Entity\EntryItem;
// 1. Log new contacts and trigger downstream CRM onboarding$wire->addHookAfter('Contacts::afterContactSaved', function (HookEvent $event): void { /** @var ContactEntry $contact */ $contact = $event->arguments(0); $isNew = (bool) $event->arguments(1); if ($isNew) { $event->wire()->log->save('contacts-crm', "New contact created: {$contact->id}"); }});
// 2. Inject custom charter booking milestones into the contact timeline$wire->addHookAfter('Contacts::collectTimelineItems', function (HookEvent $event): void { /** @var EntryItem $record */ $record = $event->arguments(0); $items = (array) $event->return; $items[] = [ 'id' => 'charter-welcome-' . $record->id, 'type' => 'charter', 'title' => 'Added to Aegean Broker Directory', 'occurred_at' => (string) $record->created, ]; $event->return = $items;});
// 3. Reassign foreign UUIDs after merge and scrub copies after GDPR erasure$wire->addHookAfter('Contacts::afterMerge', function (HookEvent $event): void { /** @var EntryItem $primary */ $primary = $event->arguments(1); $duplicateId = (string) $event->arguments(2); $event->wire()->log->save('contacts-merge', "Merged {$duplicateId} into {$primary->id}");});
$wire->addHookAfter('Contacts::afterAnonymize', function (HookEvent $event): void { /** @var EntryItem $contact */ $contact = $event->arguments(0); $reason = (string) $event->arguments(1); $event->wire()->log->save('contacts-gdpr', "Anonymized {$contact->id} ({$reason})");});Transactional Composition
Section titled “Transactional Composition”When composing multiple Contacts writes that trigger deferred hooks or webhooks, wrap them in $contacts->runInTransaction() (and queue post-commit actions via $contacts->deferPostCommit()):
<?php
declare(strict_types=1);
namespace ProcessWire;
$contacts = Contacts::requireInstance($this);
$contacts->runInTransaction(function () use ($contacts, $org, $contact): void { $contacts->addresses()->upsertFor($contact, [ 'address_type' => 'office', 'line1' => 'Skopea Marina Pier 4', 'city' => 'Gocek', 'country_code' => 'TR', ]); $contacts->deferPostCommit(static function () use ($contact): void { // Runs only after the database transaction commits cleanly });});All 7 CLI Commands (php vendor/bin/wire)
Section titled “All 7 CLI Commands (php vendor/bin/wire)”| Command | Flags & Usage |
|---|---|
contacts:doctor |
--json (verifies blueprints, permissions, settings, and PII-free aggregate KPIs). |
contacts:scaffold:user |
-t/--template=user, -s/--sections=profile,memberships, -p/--prefix=contact_, --style=card|plain|fieldset, --allow-user-template, --dry-run, --json. |
contacts:seed |
--mode=skip|upsert, --only=roles,tags,organizations,contacts,notes, --with-demo, --dry-run, --force, --json. |
contacts:dedupe |
--scope=contacts|organizations, --fuzzy, --auto-merge, --dry-run, --force, --json. |
contacts:export |
--type=contacts|organizations|notes|roles|tags, --format=csv|json|vcf, --profile=contacts|google|microsoft|apple|zoho, --tag=<code|uuid>, --output-file=<path>, --json. |
contacts:import |
<file>, --type=contacts|organizations, --format=auto|csv|json|vcf, --profile=auto|contacts|google|microsoft|apple|zoho, --mode=upsert|skip, --dry-run, --json. |
contacts:retention |
--action=anonymize|archive, --days=<int>, --limit=500, --dry-run, --force, --json. |
Troubleshooting
Section titled “Troubleshooting”contacts:scaffold:user Refuses to Modify the user Template
Section titled “contacts:scaffold:user Refuses to Modify the user Template”- Mutating ProcessWire’s system
usertemplate is opt-in by design. Pass--allow-user-templateexplicitly (and test with--dry-run --jsonfirst).
mergeContacts() Throws a Linked-User Conflict Error
Section titled “mergeContacts() Throws a Linked-User Conflict Error”- Two contacts linked to different positive
linked_user_idaccounts cannot be merged automatically. Unlink or resolve the duplicate ProcessWire user account first before merging.
Fuzzy Duplicate Clusters Are Not Merged by contacts:dedupe --auto-merge
Section titled “Fuzzy Duplicate Clusters Are Not Merged by contacts:dedupe --auto-merge”- By design,
--fuzzy(75% Matchname + organization/domain) is strictly for manual review in Setup -> Contacts -> Duplicates and is never auto-merged by CLI.
Headless POST /api/v1/contacts Returns Only {created: false, matchedBy, id}
Section titled “Headless POST /api/v1/contacts Returns Only {created: false, matchedBy, id}”- The caller holds
contacts:writewithoutcontacts:readorcontacts:admin.ContactsHeadlessProviderintentionally redacts pre-existing contact PII on write-only tokens.
Outbound Webhook Payload, Demo Mode & Localization
Section titled “Outbound Webhook Payload, Demo Mode & Localization”When Contacts::forwardWebhook forwards lifecycle events (contacts.created, contacts.updated, contacts.merged, contacts.anonymized) to Headless or custom sinks, the JSON payload follows this structure:
{ "event": "contacts.merged", "timestamp": "2026-06-15T11:20:00Z", "data": { "scope": "contacts", "primary_id": "0196f8d2-3c1a-7b40-9e12-8a4c5d6e7f01", "duplicate_id": "0196f8d2-9a0b-7c10-8d33-1b2c3d4e5f02" }}- Demo Mode (
$config->demo = true): Blocks destructive merges, bulk imports, and GDPR anonymization writes so demo environments cannot lose seeded directory data. - 6-Locale Translation Packs: Bundled CSV packs (
en,tr,de,fr,es,ru) live insite/modules/Contacts/languages/. Import the matching.csvfile under Setup -> Languages -> [Language] -> Site Translation Files.