Hooks, Endpoints & Integrations
Blocks exposes clean hook points, runtime registries, four hardened HTTP endpoints, and eight lazily booted optional module integrations.
Hookable Methods
Section titled “Hookable Methods”| Hook | Arguments & Return | Timing | What It Does |
|---|---|---|---|
Blocks::registerBlockPacks |
(Blocks $blocks): void |
After | Fires during lazy block catalog boot so modules can register custom BlockPackInterface packs. |
Blocks::registerPanelRoles |
(Blocks $blocks): void |
After | Fires during panel discovery so modules can register custom panel_role layout types (for example megamenu or drawer). |
Blocks::resolveBlockParams |
(Page|EntryItem $entity, array $block, DependencyCollector $deps): array |
After | Resolves and overrides runtime parameters for a block node right before rendering; add cache tags via $deps->addTag(). |
FieldtypeBlocks::getFieldSetups |
(): array |
After | Customizes preset setups offered when creating a Blocks: Visual Studio field. |
InputfieldBlocks::translations |
(): array |
After | Returns localized UI string overrides for the Visual Studio and block picker Inputfield. |
ProcessBlocks::translations |
(): array |
After | Returns localized UI string overrides for the Setup -> Blocks React workspace. |
Register a Block Pack & Inject Runtime Parameters
Section titled “Register a Block Pack & Inject Runtime Parameters”<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Blocks\Cache\DependencyCollector;
$wire->addHookAfter('Blocks::registerBlockPacks', function (HookEvent $event): void { /** @var Blocks $blocks */ $blocks = $event->arguments(0); $blocks->registerBlockPack(new AegeanCharterBlockPack());});
$wire->addHookAfter('Blocks::resolveBlockParams', function (HookEvent $event): void { $block = (array) $event->arguments(1); /** @var DependencyCollector $deps */ $deps = $event->arguments(2); $params = (array) $event->return;
if (($block['type'] ?? '') === 'fleet_highlights') { $deps->addTag('charter:fleet'); $params['season'] = 'summer'; $event->return = $params; }});Runtime Enrichers & Dynamic Field Options
Section titled “Runtime Enrichers & Dynamic Field Options”Register dynamic dropdown options or runtime node enrichers in site/ready.php without modifying block YAML files:
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Blocks\Cache\DependencyCollector;use Totoglu\Entries\Entity\EntryItem;
$blocks = $wire->blocks;if ($blocks instanceof Blocks) { $blocks->registerFieldOptionsProvider('pricing_table', 'plan_group', static function (): array { return [ 'starter' => 'Starter Plans', 'enterprise' => 'Enterprise Plans', ]; });
$blocks->registerBlockTypeEnricher( 'pricing_table', static function (array $node, EntryItem $block, DependencyCollector $deps, array $context): array { $deps->addTag('pricing:plans'); $node['values']['currency'] = 'EUR';
return $node; } );}Public & Admin HTTP Endpoints
Section titled “Public & Admin HTTP Endpoints”| Route | Method | Access | Purpose |
|---|---|---|---|
/_blocks/smart |
GET / HEAD |
Public (HMAC-signed token) |
Returns paginated, sorted, and filtered Smart Content JSON slices verified by SignedSmartQueryCodec. |
/_blocks/preview |
POST |
Authenticated (superuser, blocks, blocks-admin, or page-edit + Page::editable() + CSRF, max 2 MB) |
Renders ephemeral zero-DB-write Visual Studio and Preset live previews with bidirectional iframe selection sync. |
/_blocks/preview-pages |
POST |
Authenticated (superuser, blocks-admin + CSRF) |
Returns searchable candidate public pages (PreviewPageResolver) for Layout and Reusable previews. |
/_blocks/studio-create |
POST |
Authenticated (superuser, blocks-admin + CSRF + !$config->demo) |
Creates a Block Preset or Reusable Block directly from a live block inside Visual Studio. |
Optional Sibling Module Integrations (src/Integration/*)
Section titled “Optional Sibling Module Integrations (src/Integration/*)”All cross-module bridges live strictly under site/modules/Blocks/src/Integration/ and boot lazily only when each target module is installed:
| Module | Automatic Integration Behavior |
|---|---|
Ai |
Registers BlocksCapabilityProvider (blocks namespace; blocks:read / blocks:write) exposing resources (pw://blocks/catalog, pw://blocks/layouts) and tools (blocks_catalog, blocks_layouts, blocks_inspect_page, blocks_patch_page, blocks_compose_page) with ontology, locked-block, and $config->demo guards (dry_run: true allowed). |
Navigation |
Populates navigation.menu_handle and navigation.parent_node_id, exposes active megamenu Panel Layouts to Navigation::panelOptions(), resolves menu / current_branch / parent_node trees + Schema.org BreadcrumbList JSON-LD, and evicts nav:* cache tags. |
Forms |
Populates form.form_slug options, attaches FormsFrontend.{css,js}, and disables caching (cacheable: false) on compositions containing rendered forms so CSRF tokens never share caches. |
Seo |
Hooks Seo::resolve to backfill empty meta descriptions and OpenGraph images from PlainHtmlExtractor. |
Headless |
Registers BlocksHeadlessProvider (blocks:read scope) exposing GET /api/v1/blocks/resolve, /api/v1/blocks/layouts/{handle}, /api/v1/blocks/panels/{handle}, and /api/v1/blocks/smart, plus OpenAPI 3.1 schemas and scoped TypeScript definitions. |
Media |
Bridges FieldtypeMedia, MediaAssetItem, and MediaAssetArray via MediaProviderBridge for field mapping, page conditions, focal-point WebP srcset, and media:<uuid> cache tags. |
Vite |
Connects BlockAssetRegistry::vite() / $renderer->useVite() to Totoglu\Vite\Vite with HMR @vite/client deduplication, manifest chunk deduplication, SRI hashes, and CSP nonces. |
Inertia |
Registers BlocksFieldDataProvider emitting BlocksInertiaPayload, BlockPageComposition, BlockNode, and BlockSmartPayload TypeScript types. |