Skip to content

fix: scope sensitive toggle to form blueprint and fieldset editors - #8

Open
andrii-trush wants to merge 1 commit into
mainfrom
feature/scope-sensitive-toggle-to-form-blueprints
Open

andrii-trush wants to merge 1 commit into
mainfrom
feature/scope-sensitive-toggle-to-form-blueprints

Conversation

@andrii-trush

Copy link
Copy Markdown
Member

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 the POST /cp/fields/edit endpoint 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:

  • The config field carries if => 'custom sensitiveFieldSupported' — conditions are a pass-through config key, so it reaches the CP untouched.
  • New resources/js/cp.js registers that condition via Statamic.$conditions.add(), shipped through ServiceProvider::$scripts.
  • It passes when the isFormBlueprint CP config flag is true, 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 in docs/OVERVIEW.md — if it ever changes upstream, failing closed would mean silently un-encrypting live fields.

Known coupling

isFormBlueprint and 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. FieldToggleScopeTest pins 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:install publishes it, and a standard Statamic site runs that from Composer's post-autoload-dump — ordinary installs and upgrades need no extra step. A deployment that skips Composer scripts or ships a prebuilt public/ must run:

php artisan vendor:publish --tag=statamic-sensitive-form-fields --force

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

  • Toggle instructions now state that only form submissions are encrypted, and what a fieldset field means.
  • Docs corrected: AGENTS.md, docs/OVERVIEW.md and docs/PLAN.md still described addon settings as living in resources/blueprints/settings.yaml; they are registered in code by ServiceProvider::registerSettings(). Creating that file would register a competing blueprint namespace and bypass the Pro-only gating of the mask field.
  • docs/OVERVIEW.md test coverage section brought in line with what is actually there (rekey command tests, corrected unit test counts, deduplicated entry).
  • README limitations note that a leftover sensitive: true on 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 --test clean.

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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant