Skip to content

Extending & Module Integration

Inertia exposes domain-agnostic base classes, interfaces, and hooks so ProcessWire modules can render interactive admin pages, frontend islands, and custom Inputfields without duplicating protocol logic.

Base Class / Interface Namespace Purpose
ProcessInertia Totoglu\Inertia\ProcessInertia Base class for ProcessWire Admin Process modules rendering Inertia views inside ProcessWire Admin or full-page shells.
MarkupInertia Totoglu\Inertia\MarkupInertia Base class for standalone mounted Inertia islands inside classic templates or InputfieldMarkup panels.
InputfieldInertia Totoglu\Inertia\InputfieldInertia Base class for custom ProcessWire Inputfield modules backed by an Inertia client component (___render(), ___renderValue(), ___processInput()).
InertiaFieldtypeInterface Totoglu\Inertia\Contract\InertiaFieldtypeInterface Contract implemented by custom Fieldtype modules (paired with InteractWithInertiaFieldtype) so ProviderRegistry serializes values and emits TypeScript types automatically.
InertiaSerializable Totoglu\Inertia\Contract\InertiaSerializable Contract for custom PHP value objects that define their own toInertiaArray() representation when passed as props.

Opt-In Constants for ScalarFieldDataProvider

Section titled “Opt-In Constants for ScalarFieldDataProvider”

Custom Fieldtype or Inputfield modules that store structured data inside standard ProcessWire columns can opt into built-in ScalarFieldDataProvider handling by declaring one of four class constants:

  • INERTIA_IS_MARKUP_FIELD: treat stored value as pre-rendered HTML markup
  • INERTIA_IS_KEYVALUE_FIELD: serialize structured key-value pair arrays
  • INERTIA_IS_LINK_FIELD: serialize polymorphic link payloads
  • INERTIA_IS_ICON_FIELD: serialize vector icon payloads

Registering Providers From a Module (Tier 2 Hook)

Section titled “Registering Providers From a Module (Tier 2 Hook)”

Third-party or first-party modules should register their DataProviders lazily through the Inertia::registerProviders hook instead of scanning files on every request:

<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Inertia\Provider\ProviderRegistry;
$this->wire()->addHookAfter('Inertia::registerProviders', function (HookEvent $event): void {
/** @var Inertia $inertia */
$inertia = $event->object;
$inertia->registerProvider(new MyModuleFieldDataProvider());
});
Hook Arguments & Return Timing What It Does
Inertia::registerProviders (): void After Fires during provider discovery so modules can register Tier 2 TemplateDataProvider or FieldDataProvider instances lazily.
Inertia::buildPageObject (PageResponse $pageResponse): array After Builds the serialized Inertia v3 Page Object (component, props, url, version). Modify $event->return to inject global metadata or request-scoped props.
Inertia::renderPageResponse (PageResponse $pageResponse): string Before / After Renders the final HTML root document or JSON Inertia payload. Hook After to log rendered components or append diagnostic headers.
MarkupInertia::render (array $props = []): string Before / After Renders a mounted standalone Inertia island inside classic templates or InputfieldMarkup panels.

Inject Shared Metadata Into Every Inertia Page Object

Section titled “Inject Shared Metadata Into Every Inertia Page Object”
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
$wire->addHookAfter('Inertia::buildPageObject', function (HookEvent $event): void {
$pageObject = (array) $event->return;
$pageObject['props']['siteRegion'] = 'aegean';
$event->return = $pageObject;
});
$wire->addHookAfter('Inertia::renderPageResponse', function (HookEvent $event): void {
/** @var \Totoglu\Inertia\PageResponse $response */
$response = $event->arguments(0);
$event->wire()->log->save('inertia-renders', "Rendered {$response->component}");
});

Next steps