Core Concepts
Mystique separates field schema definition (resources on disk or inline JSON) from persisted values (one JSON column per FieldtypeMystique field).
Architecture Overview
Section titled “Architecture Overview”flowchart LR
RES["Resource File (PHP Array / Closure / JSON) or Inline JSON"] --> REG["ResourceRegistry + FieldsetExpander"]
REG --> CACHE["WireCache (Mystique.Resources)"]
REG --> FORM["FormManager -> InputfieldMystique"]
FORM --> SLEEP["ValueSerializer + FieldtypeMystique::sleepValue"]
SLEEP --> DB["MySQL field_<name>.data (LONGTEXT / JSON)"]
DB --> WAKE["FieldtypeMystique::wakeupValue -> MystiqueValue"]
DB --> QUERY["MystiqueQueryEngine ($pages->find)"]
Resource Discovery Locations
Section titled “Resource Discovery Locations”Totoglu\Mystique\Finder and ResourceRegistry automatically discover resource files matching Mystique.<name>.php or Mystique.<name>.json in two places:
- Site templates:
site/templates/configs/Mystique.<name>.{php,json}(appears as<Title> (templates)with caller IDtemplates.<name>). - Installed modules:
site/modules/<Module>/configs/Mystique.<name>.{php,json}(appears as<Title> (<module>)with caller ID<module>.<name>).
Reusable partials live under site/templates/configs/fieldsets/*.{php,json} or site/modules/*/configs/fieldsets/*.{php,json} and are imported with @fieldset:<name>.
Static vs. Dynamic Resources & Caching
Section titled “Static vs. Dynamic Resources & Caching”- Static PHP arrays, JSON files, and inline JSON: Expanded once (including all transitive
@fieldset:dependencies) and cached inWireCacheunder theMystique.Resourcesnamespace. Cache keys includefilemtime,filesize, and the active language ID, so editing any resource or imported@fieldset:file invalidates the cache on the very next request. - Dynamic PHP Closure resources: Returning
static function (?Page $page = null, ?Field $field = null, ?MystiqueValue $value = null): arrayruns live on every page edit and is never cached across pages or values. - Schema synchronization: Both
FieldtypeMystique::___wakeupValue()and___sleepValue()synchronize stored JSON against the active schema: newly added subfields immediately receive theirdefaultValue, and removed subfields are dropped cleanly on save.
MystiqueValue
Section titled “MystiqueValue”Reading $page->my_mystique returns a Totoglu\Mystique\MystiqueValue (extending ProcessWire\WireData). Subfield access ($page->my_mystique->headline) automatically resolves native ProcessWire types (Page, PageArray, Pageimage, Pagefile, formatted Datetime, and active-language values) based on $page->of().