.json (the per-item format documentation); * - variants/build.php — when new option keys are auto-added to a * variant json (row 246), their format hint is added to "_formats" too. * * The hint is documentation only; build.php never reads "_formats". */ if (!function_exists('option_format_hint')) { /** * @param DOMElement $opt an / element of the mother config.xml * @return string format hint, e.g. 'on|off', 'hex color, e.g. #123456' */ function option_format_hint(DOMElement $opt): string { $key = $opt->nodeName; $type = $opt->getAttribute('type'); $options = $opt->getAttribute('options'); $parent = $opt->getAttribute('parent'); // color-chooser pair: = mode dropdown, custom = hex picker if ($type === 'dropdown' && $options === 'default|defaultbackgroundcolor|color1|color2|color3|other') { return "chooser mode: one of $options — when 'other', put the hex in {$key}custom"; } if ($type === 'colorpicker') { // a colorpicker always stores a hex value (the on|off options attr is // only UI chrome); the custom pickers feed the chooser dropdowns $hint = "hex color, e.g. #123456"; if (substr($key, -6) === 'custom') { $base = substr($key, 0, -6); $hint .= " (used when $base = 'other')"; } elseif ($parent !== '') { $hint .= " (used when $parent = 'other')"; } return $hint; } if ($type === 'buttons') { return $options !== '' ? "one of: $options" : "on|off"; } if ($type === 'checkbox') { return "on|off (checkbox)"; } if ($type === 'fontselect') { return "font value slug or 'base' (= same as base font), e.g. \"inter\""; } if ($type === 'dropdown') { if ($key === 'font') { return "font value slug, e.g. \"inter\" (dropdown optgroups; a variant's default = its first fontOptions value)"; } return $options !== '' ? "one of: $options" : "dropdown value"; } if ($type === 'imagefile') { return "off | theme-relative image path, e.g. ./files/logo.png (gif|ico|jpg|jpeg|png only — SVG is rejected)"; } if ($type === 'text') { if (preg_match('/radius/i', $key)) { return "CSS length in px or rem, e.g. 5px (border-radius; NOT seconds)"; } if (preg_match('/margin|height/i', $key)) { return "plain px number, e.g. 15 (margins 0-100)"; } if (preg_match('/distance/i', $key)) { return "length, e.g. 20px or 1.5rem"; } if ($key === 'questionborderstyle') { return "CSS border-style keyword, e.g. solid|dashed|dotted|none"; } return "free text"; } if ($type === 'duration') { return "duration in seconds, e.g. 300"; } return "value of type '$type'"; } /** * Build the full key => hint map from a loaded mother config.xml DOMDocument. * * @return array in mother config order */ function option_format_map(DOMDocument $doc): array { $map = []; foreach ((new DOMXPath($doc))->query('//options/*') as $opt) { if ($opt instanceof DOMElement) { $map[$opt->nodeName] = option_format_hint($opt); } } return $map; } }