Skip to content

PHP API, Hooks & Extending

Entries exposes hookable ___ methods across its CRUD, draft, revision, query, transfer, Managed Tables, and Page Connector pipelines so project code and sibling modules can extend behavior without modifying module files.

Normalize fields before saving (saveReady)

Section titled “Normalize fields before saving (saveReady)”
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
$wire->addHookBefore('Entries::saveReady', function (HookEvent $event): void {
/** @var \Totoglu\Entries\Entity\EntryItem $item */
$item = $event->arguments(0);
if ($item->type !== 'seasons') {
return;
}
$item->set('code', strtoupper(trim((string) $item->get('code'))));
});
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
$wire->addHookAfter('Entries::saved', function (HookEvent $event): void {
/** @var \Totoglu\Entries\Entity\EntryItem $item */
$item = $event->arguments(0);
$isNew = (bool) $event->arguments(1);
if ($item->type === 'release_notes' && $isNew) {
$event->wire()->log->save('releases', "Created release note {$item->id}");
}
});

Authorize Mutations & React to Managed Table Inserts

Section titled “Authorize Mutations & React to Managed Table Inserts”
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Entries\Entity\EntryItem;
$wire->addHookAfter('Entries::canMutateItem', function (HookEvent $event): void {
/** @var EntryItem $item */
$item = $event->arguments(0);
$action = (string) $event->arguments(1);
$user = $event->arguments(3) ?? $event->wire()->user;
if ($item->type === 'charter_bookings' && $action === 'delete' && !$user->isSuperuser()) {
$event->return = false;
}
});
$wire->addHookAfter('TableService::inserted', function (HookEvent $event): void {
$handle = (string) $event->arguments(0);
$id = (string) $event->arguments(1);
if ($handle === 'availability_holds') {
$event->wire()->log->save('entries-tables', "Inserted hold #{$id}");
}
});
Hook Arguments & Return Timing What It Does
Entries::saveReady (EntryItem $item, bool $isNew): void Before Fires right before validation and database persistence. Ideal for normalizing fields or enforcing invariants.
Entries::saved (EntryItem $item, bool $isNew): void After Fires immediately after save and search index update.
Entries::save / saveMany (EntryItem $item): bool / (iterable $items): int Before / After Persists one or many EntryItem records inside a transaction.
Entries::delete / deleteMany (EntryItem|string $item): bool / (iterable $items): int Before / After Permanently deletes one or many entry records and cleans up references.
Entries::trash / restore / emptyTrash (EntryItem|string $item): bool / (?string $type = null, ?int $olderThanDays = null): int Before / After Moves records to trash, restores them, or purges aged trash entries.
Entries::cloneItem / updateMany / processScheduledPublications (EntryItem|string $item, array $overrides = [], bool $save = true): EntryItem / (string $selector, array $values): int / (?string $type = null): array Before / After Clones records, runs bulk field updates, or publishes scheduled records whose publish window has arrived.
Entries::collection / single / default / setDefault (string $classOrType): EntryCollection|EntryItem|?EntryItem After Resolves collection builders, single-entry records, or scoped default records.
Entries::find / findOne / get / getMany / findPaginated / findCursor / findRaw / findMany / count / search (string $selector = '', ...) Before / After Executes selector queries, paginated/cursor feeds, raw projections, chunked generators, counts, and full-text searches.
Entries::aggregate / groupBy / distinct (string $selector, ...) After Runs SQL-backed COUNT/SUM/AVG/MIN/MAX aggregates, grouped rollups, and distinct value lists.
Entries::referencingPages / referencingEntries (EntryItem|string $item, ...) After Finds ProcessWire Pages or EntryItems referencing a target record.
Entries::revisions / restoreRevision / restoreRevisionFields / diffRevision (EntryItem|string $item, ...) Before / After Lists revision history, restores full or partial snapshots, or computes field-level diffs.
Entries::saveDraft / drafts / countDrafts / hasDraft / getDraft / diffDraft / publishDraft / discardDraft / discardAllDrafts (EntryItem|string $item, ...) Before / After Manages named/auto drafts, diffs against live values, and atomic draft publishing or discarding.
Entries::createPreviewToken / resolvePreviewToken (EntryItem|string $item, ?string $draft = null, int $ttlSeconds = 3600): string / (string $token, bool $allowLiveFallback = false): ?EntryItem After Issues and verifies signed time-limited preview tokens for live or draft records.
Entries::canMutateItem / canReadSourceMedia (EntryItem $item, string $action = 'edit', ?string $fieldName = null, ?User $user = null): bool / (?EntryItem $sourceItem, Blueprint $sourceBlueprint, string $fieldName, User $user): ?bool After Extends RBAC checks for record mutations and isolated media access.
Entries::resolveReferenceEditUrl / collectEditorExtensions / resolvePivotFields (EntryItem $refEntry, Blueprint $refBp): string / (DualSourceEditorSpec $spec, array $context = []): array / (...): array After Customizes Referenced By edit links, injects React editor extensions (beforeForm, afterForm, sidebar), or reshapes pivot fields per target.
Entries::reindex / clearCache / getActivityLog / seed (?string $type = null, ...) Before / After Rebuilds search indexes, flushes caches, queries activity logs, or seeds blueprint demo data.
Entries::export / exportJson / exportJsonToFile / exportCsv / exportCsvToFile / exportIcs / exportArchive (array $options = []) / (string $type, array $options = []) Before / After Exports records to structured arrays, JSON strings/files, CSV strings/files, iCalendar .ics, or portable ZIP archives.
Entries::import / previewCsv / importCsv / importArchive (array|string $payload, array $options = []): array Before / After Previews and imports JSON, CSV, or portable ZIP archive bundles.
TableService::inserted / updated / deleted / restored (string $handle, int|string|null $id, ...): void After Fires after Managed SQL Table row mutations (with sensitive columns redacted).
FieldtypeEntries::getFieldSetups (): array After Customizes preset field setups shown when creating a new FieldtypeEntries field.
InputfieldEntries::getSelectableItems / InputfieldEntries::renderItemLabel / InputfieldEntries::translations (?Page $page = null, string $filterSelector = ''): EntryArray / (EntryItem $item): string / (): array After Filters selectable reference items, formats picker labels, or overrides Inputfield UI strings.
InputfieldEntriesBlocks::translations / MarkupReactCalendar::translations / MarkupReactKanban::translations / ProcessEntries::translations (): array After Returns localized UI string catalogs for the Blocks editor, Calendar view, Kanban board, and Setup -> Entries workspace.
EntryFilesManager::path / EntryFilesManager::url / VirtualFileHost::editUrl (): string / (array|bool|string $options = []): string After Resolves isolated media storage paths, public URLs, and virtual host edit URLs.

Registering extra blueprint paths and lazy resolvers

Section titled “Registering extra blueprint paths and lazy resolvers”

You can register additional blueprint directories (for example, inside a module or site feature package) or register lazy resolvers so module schemas parse only when actually queried or edited:

<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Entries\Schema\SchemaRegistry;
$entries = $this->wire()->entries;
// Register an additional blueprint directory (symlinks and path traversal are rejected)
$entries->addPath(__DIR__ . '/blueprints');
// Zero-boot-cost lazy blueprint resolver
$entries->registry()->registerLazyResolver(
'my-module-',
static function (string $name, SchemaRegistry $registry): ?array {
if ($name === 'my-module-settings') {
return [
'title' => 'My Module Settings',
'kind' => 'single',
'hidden' => true,
'fields' => [
'enabled' => ['type' => 'toggle', 'label' => 'Enabled', 'default' => true],
],
];
}
return null;
},
'my-module-resolver'
);

Building downstream modules on top of Entries

Section titled “Building downstream modules on top of Entries”

When building a ProcessWire module that stores its data in Entries:

  • Internal visibility: Mark module-owned blueprints hidden: true so they appear in your module’s own workspace instead of cluttering Setup -> Entries. Keep reusable @fieldset:* definitions hidden: false when editors attach them to pages.
  • Unified Dual-Source editor and viewports: Reuse $entries->recordEditor(), $entries->viewports(), $entries->formPipeline(), and $entries->pageBridge()->attachFieldsetToTemplate() so your module can edit both Entries records and ProcessWire Page records inside its own admin workspace without rebuilding forms, tabs, CSRF checks, or upload handling.
  • Zero-orphan uninstall: Inside your module’s ___uninstall(), call $entries->purgeTypes($allModuleBlueprintTypes, $lazyResolverIds) to remove all module-owned records, child blocks, revisions, drafts, activity logs, index rows, isolated media folders, and dangling page references in one call.
  • Internal Editor Panel Route (/_entries/editor-panel): Authenticated admin requests use /_entries/editor-panel to load embedded DualSourceRecordEditor panels and relation pickers with CSRF and RBAC checks. Exclude /_entries/* from any reverse-proxy or CDN HTML cache.
  • Dev -> Staging -> Production Sync: Keep file-backed blueprints under site/entries/ in Git so schema changes deploy atomically with your code, and run php vendor/bin/wire entries:doctor --json on deploy.

Next steps