Skip to content

PHP API, Hooks & Troubleshooting

For the complete class and method dictionary (Mystique, FieldtypeMystique, InputfieldMystique, MystiqueValue, FormManager, MystiqueFilesManager), read site/modules/Mystique/API.md or run php index.php docs get-text FieldtypeMystique.

  • Clear resource cache: $fieldtype->clearCache() or $fieldtype->resetResources() (also flushed automatically on Fields::saved and Modules::refresh).
  • Rename a subfield across all existing pages transactionally:
<?php
declare(strict_types=1);
namespace ProcessWire;
$field = $this->wire()->fields->get('yacht_specs');
if ($field instanceof Field && $field->type instanceof FieldtypeMystique) {
$updatedRows = $field->type->renameSubfieldData($field, 'old_rate_key', 'pricing_weekly_rate');
}
  • ProcessWire Boost integration: MystiqueFieldSchemaExtender (.agents/schema/field-extenders.php) automatically exposes Mystique field settings and expanded subfield definitions to ProcessWire Boost (pw_schema_read and .agents/map.json).

Hookable Methods (FieldtypeMystique & InputfieldMystique)

Section titled “Hookable Methods (FieldtypeMystique & InputfieldMystique)”
Hook Arguments & Return Timing What It Does
FieldtypeMystique::markupValue (Page $page, Field $field, mixed $value = null, string $property = ''): string After Formats a Mystique field or single subfield as human-readable HTML markup (used in Lister columns and admin summaries).
FieldtypeMystique::wakeupValue (Page $page, Field $field, mixed $value): MystiqueValue After Hydrates stored JSON into a schema-synchronized MystiqueValue instance.
FieldtypeMystique::sleepValue (Page $page, Field $field, mixed $value): array Before / After Serializes a MystiqueValue into ['data' => $json] right before database persistence.
FieldtypeMystique::formatValue (Page $page, Field $field, mixed $value): MystiqueValue After Applies output formatting (useEntityEncode, dateOutputFormat, single Pageimage/Pagefile unwrapping) when $page->of(true).
FieldtypeMystique::getSelectorInfo (Field $field, array $data = []): array After Exposes subfield labels, option lists, and supported selector operators to ProcessWire Lister / InputfieldSelector.
FieldtypeMystique::getConfigAllowContext (Field $field): array After Controls which FieldtypeMystique settings can be overridden per template context.
InputfieldMystique::render (): string Before / After Renders the full dynamic Inputfield form inside the ProcessWire Page editor.
InputfieldMystique::renderValue (): string After Renders the read-only value view when a Mystique field is locked or viewed read-only.
InputfieldMystique::processInput (WireInputData $input): InputfieldMystique Before / After Processes submitted form values, nested fieldsets, and optional JSON imports.
InputfieldMystique::getConfigInputfields (): InputfieldWrapper After Builds the Input tab configuration fields for InputfieldMystique.
InputfieldMystique::getConfigAllowContext (Field $field): array After Controls which InputfieldMystique settings can be overridden per template context.
site/ready.php
<?php
declare(strict_types=1);
namespace ProcessWire;
use Totoglu\Mystique\MystiqueValue;
// 1. Customize how a subfield renders inside ProcessWire Lister columns
$wire->addHookAfter('FieldtypeMystique::markupValue', function (HookEvent $event): void {
/** @var Field $field */
$field = $event->arguments(1);
$value = $event->arguments(2);
$property = (string) $event->arguments(3);
if ($field->name === 'yacht_specs' && $property === 'pricing_weekly_rate' && $value instanceof MystiqueValue) {
$rate = number_format((float) $value->get('pricing_weekly_rate'), 0);
$currency = (string) $value->get('pricing_currency_code');
$event->return = "<strong>{$rate} {$currency}</strong> / week";
}
});
// 2. Append a computed helper value whenever yacht_specs is formatted for templates
$wire->addHookAfter('FieldtypeMystique::formatValue', function (HookEvent $event): void {
/** @var Field $field */
$field = $event->arguments(1);
$value = $event->return;
if ($field->name === 'yacht_specs' && $value instanceof MystiqueValue) {
$value->set('is_gulet', $value->get('yacht_class') === 'gulet');
$event->return = $value;
}
});

Mystique ships bundled 6-locale CSV translation packs (en, tr, de, fr, es, ru) inside site/modules/Mystique/languages/. To translate the admin field settings and editor UI, import the matching .csv file under Setup -> Languages -> [Language] -> Site Translation Files.

New Resource File Does Not Appear Under Input -> Resource

Section titled “New Resource File Does Not Appear Under Input -> Resource”
  • Confirm the filename matches Mystique.<name>.php or Mystique.<name>.json inside site/templates/configs/ (or site/modules/<Module>/configs/), is not a symlink outside site/, and click Modules -> Refresh (or call $fieldtype->clearCache()).

Mystique::IMAGE Returns Pageimages Instead of Pageimage in CLI or Hooks

Section titled “Mystique::IMAGE Returns Pageimages Instead of Pageimage in CLI or Hooks”
  • Just like core ProcessWire image fields, maxFiles => 1 returns a single Pageimage|null only when $page->of(true). In CLI scripts or hooks where $page->of(false) is active, call $page->yacht_specs->hero_image->first() (or enable $page->of(true) before reading).

Circular @fieldset: Import Throws WireException

Section titled “Circular @fieldset: Import Throws WireException”
  • Check that @fieldset:a does not directly or indirectly import @fieldset:a again. Extract shared base fields into a separate leaf partial under site/templates/configs/fieldsets/.

Next steps