Skip to content

Core Concepts

Mystique separates field schema definition (resources on disk or inline JSON) from persisted values (one JSON column per FieldtypeMystique field).

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)"]

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 ID templates.<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 PHP arrays, JSON files, and inline JSON: Expanded once (including all transitive @fieldset: dependencies) and cached in WireCache under the Mystique.Resources namespace. Cache keys include filemtime, 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): array runs 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 their defaultValue, and removed subfields are dropped cleanly on save.

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().

Next steps