Repository navigation
fix: scope sensitive toggle to form blueprint and fieldset editors - #8
Open
andrii-trush wants to merge 1 commit into
Open
andrii-trush wants to merge 1 commit into
andrii-trush wants to merge 1 commit into
Conversation
The "Sensitive (encrypted at rest)" toggle was appended to the Text and Textarea fieldtypes via appendConfigField(), which writes into a static, per-fieldtype-class registry with no blueprint context. The toggle therefore rendered in every blueprint editor — collections, taxonomies, users, globals — where the addon encrypts nothing and enabling it is a silent no-op. Scope it in the Control Panel instead: the config field carries `if => 'custom sensitiveFieldSupported'`, and a new CP script registers that condition. It passes on the `isFormBlueprint` config flag or on the form blueprint / fieldset editor paths, and fails closed otherwise. Hiding is non-destructive — the field-settings panel posts the full value set rather than the condition-filtered one, so a hidden toggle never strips a stored `sensitive: true`. Both signals are internal CP surface. FieldToggleScopeTest pins the two route paths against Statamic's own route definitions and asserts the JS condition name matches the one referenced from PHP, so an upstream change fails a test instead of silently hiding the toggle. Also corrects the toggle instructions to state that only form submissions are encrypted, and fixes stale docs that still described addon settings as living in resources/blueprints/settings.yaml. Reported by Thomas Vantuycom. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Sensitive (encrypted at rest) toggle showed up on every text and textarea field in every blueprint — collections, taxonomies, users, globals — not just form blueprints. Enabling it outside a form is a silent no-op: only form submissions are ever encrypted.
Reported by Thomas Vantuycom by email.
Root cause:
appendConfigField()writes into a static, per-fieldtype-class registry that carries no blueprint context, and thePOST /cp/fields/editendpoint serving the field-settings panel is never told which blueprint is being edited. There is no server-side signal to scope on.Fix
Scope it in the Control Panel:
if => 'custom sensitiveFieldSupported'— conditions are a pass-through config key, so it reaches the CP untouched.resources/js/cp.jsregisters that condition viaStatamic.$conditions.add(), shipped throughServiceProvider::$scripts.isFormBlueprintCP config flag istrue, or when the path is the form blueprint editor (/fields/blueprints/forms/) or the fieldset editor (/fields/fieldsets/). Otherwise it fails closed.Fieldsets are included because a fieldset can be imported into a form blueprint, where the setting does take effect.
Failing closed is safe because hiding is non-destructive: the field-settings panel posts the full value set rather than the condition-filtered one, so a hidden toggle never strips a stored
sensitive: true. That trade-off is documented indocs/OVERVIEW.md— if it ever changes upstream, failing closed would mean silently un-encrypting live fields.Known coupling
isFormBlueprintand both route paths are internal CP surface, not documented API. In the form blueprint editor either signal alone suffices; in the fieldset editor the path is the only signal there is.FieldToggleScopeTestpins both paths against Statamic's own route definitions and asserts the JS condition name matches the one referenced from PHP, so an upstream rename fails a test rather than silently hiding the toggle from customers.Deployment note
The CP script is a published asset.
php artisan statamic:installpublishes it, and a standard Statamic site runs that from Composer'spost-autoload-dump— ordinary installs and upgrades need no extra step. A deployment that skips Composer scripts or ships a prebuiltpublic/must run:Without the script the condition is unregistered, Statamic's validator returns
false, and the toggle stays hidden everywhere — including the form blueprint editor. Called out in both README and CHANGELOG.Also in this PR
AGENTS.md,docs/OVERVIEW.mdanddocs/PLAN.mdstill described addon settings as living inresources/blueprints/settings.yaml; they are registered in code byServiceProvider::registerSettings(). Creating that file would register a competing blueprint namespace and bypass the Pro-only gating of themaskfield.docs/OVERVIEW.mdtest coverage section brought in line with what is actually there (rekey command tests, corrected unit test counts, deduplicated entry).sensitive: trueon a non-form blueprint is now hidden in the CP and can only be removed by editing the blueprint YAML.Testing
vendor/bin/phpunit— 37 tests, 84 assertions, all passing.vendor/bin/pint --testclean.5 new tests in
FieldToggleScopeTest: the config field carries the condition on both fieldtypes, the script implements the condition name PHP references, the script's route paths match Statamic's routes, and the script is registered and present at the declared path.Not covered by tests: the browser behaviour of the condition itself.
🤖 Generated with Claude Code