Skip to content

[7418] plugin - serializers/retrievers/validators - #8882

Draft
jvega190 wants to merge 1 commit into
craftersoftware:developfrom
jvega190:7418-plugin-retrievers-serializers-validators
Draft

[7418] plugin - serializers/retrievers/validators#8882
jvega190 wants to merge 1 commit into
craftersoftware:developfrom
jvega190:7418-plugin-retrievers-serializers-validators

Conversation

@jvega190

@jvega190 jvega190 commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

#7418

Summary by CodeRabbit

  • New Features
    • Added plugin support for custom value retrieval, serialization, and field validation.
    • Forms now preload required control plugins before initializing create and edit forms.
    • Exposed field rendering and plugin control integration through the Forms Engine.
  • Bug Fixes
    • Improved plugin loading cleanup and handling of preload failures.
    • Preserved configured rich-text styles, including inline and dark-mode behavior.
  • Documentation
    • Updated Forms Engine and plugin integration guidance with the new capabilities.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

FE2 control plugins now support value retrieval, serialization, and validation hooks. Forms Engine preloads referenced plugins before form initialization. The controls host exposes hook lookups and FormsEngineField. Built-in mappings retain precedence.

Changes

FE2 control plugin lifecycle

Layer / File(s) Summary
Plugin contracts and registration
studio-ui/ui/app/src/models/PluginDescriptor.ts, studio-ui/ui/app/src/services/plugin.ts, studio-ui/ui/app/src/components/FormsEngine/controls/registry.ts, studio-ui/ui/app/src/components/FormsEngine/lib/controlValueTypes.ts
Plugin contributions accept optional retriever, serializer, and validator hooks. Registration validates and stores these hooks. The registry refreshes hooks during same-owner re-registration and exposes lookup functions.
Value and validation resolution
studio-ui/ui/app/src/components/FormsEngine/lib/valueRetrievers.ts, studio-ui/ui/app/src/components/FormsEngine/lib/valueSerializers.ts, studio-ui/ui/app/src/components/FormsEngine/lib/validators.ts, studio-ui/ui/app/src/components/FormsEngine/components/TableOfContents.tsx
Built-in mappings take precedence. Plugin hooks handle unknown control types. Validator lookup is shared by validation and table-of-contents rendering.
Plugin preload and form initialization
studio-ui/ui/app/src/components/FormsEngine/lib/controlPluginLoader.ts, studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx
Nested fields are scanned for unique plugin locators. Plugins load before create and edit values are parsed. Failed loads are removed from cache and asynchronous initialization stops after disposal.
Host UI contract and documentation
studio-ui/ui/app/src/components/FormsEngine/dataSources/host.ts, studio-ui/docs/type-builder-forms-engine.md, studio-ui/docs/type-builder-forms-engine-plugins.md, studio-ui/ui/app/src/components/FormsEngine/lib/rteUtils.ts
The controls host exposes hook lookups and FormsEngineField. Documentation describes bare plugin controls, validation chrome, hook precedence, and preload behavior. TinyMCE content stylesheet fallback behavior is updated.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Plugin
  participant registerPlugin
  participant ControlRegistry
  participant FormsEngine
  participant PluginLoader

  Plugin->>registerPlugin: provide control hooks
  registerPlugin->>ControlRegistry: register contribution
  FormsEngine->>PluginLoader: preload plugins for form fields
  PluginLoader-->>FormsEngine: resolve loaded plugins
  FormsEngine->>ControlRegistry: resolve retriever, serializer, or validator
  ControlRegistry-->>FormsEngine: return registered hook
Loading

Possibly related PRs

Suggested reviewers: jmendeza, rart

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: adding plugin serializers, retrievers, and validators.
Description check ✅ Passed The description provides the required ticket reference, and the referenced objective matches the documented changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@studio-ui/docs/type-builder-forms-engine.md`:
- Around line 667-670: Synchronize the Progress and Open decisions sections in
the Forms Engine documentation with the completed control cleanup: remove or
mark resolved the entries for retired IDs link-input, link-textarea,
linked-dropdown and the remapped disabled/internal-name aliases, ensuring no
unresolved null-map-slot item remains.

In `@studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx`:
- Around line 539-543: In
studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx:539-543, update the
preload promise handling around initCreateForm to set the preparation error and
prevent initCreateForm from running when preloadControlPluginsForFields fails.
Apply the same behavior in
studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx:586-621: set the
preparation error and do not call createParsedValuesObject after preload
failure; retain the existing success paths.
- Around line 539-546: Update the embedded-component initialization flow around
prepareEmbeddedItemForm and invokePrepareFn so the embedded content type’s
fields are preloaded before invokePrepareFn parses or validates values. Reuse
the existing preloadControlPluginsForFields mechanism, awaiting or chaining it
before invokePrepareFn, while preserving the current parent-field preload and
initCreateForm behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 98e61389-0047-4be3-bb0d-ac26f0c1ae00

📥 Commits

Reviewing files that changed from the base of the PR and between cdfede1 and 60a6f0a.

📒 Files selected for processing (14)
  • studio-ui/docs/type-builder-forms-engine-plugins.md
  • studio-ui/docs/type-builder-forms-engine.md
  • studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx
  • studio-ui/ui/app/src/components/FormsEngine/components/TableOfContents.tsx
  • studio-ui/ui/app/src/components/FormsEngine/controls/registry.ts
  • studio-ui/ui/app/src/components/FormsEngine/dataSources/host.ts
  • studio-ui/ui/app/src/components/FormsEngine/lib/controlPluginLoader.ts
  • studio-ui/ui/app/src/components/FormsEngine/lib/controlValueTypes.ts
  • studio-ui/ui/app/src/components/FormsEngine/lib/rteUtils.ts
  • studio-ui/ui/app/src/components/FormsEngine/lib/validators.ts
  • studio-ui/ui/app/src/components/FormsEngine/lib/valueRetrievers.ts
  • studio-ui/ui/app/src/components/FormsEngine/lib/valueSerializers.ts
  • studio-ui/ui/app/src/models/PluginDescriptor.ts
  • studio-ui/ui/app/src/services/plugin.ts

Comment on lines +667 to +670
- **2026-08-07** — Expose `FormsEngineField` on `craftercms.formsEngine.controls`. Plugin controls render bare (built-ins wrap themselves), so a failing plugin validator previously showed only in the ToC; wrapping in the host field chrome restores parity (label, invalid styling, validity messages).
- **2026-08-07** — Plugin control validators: optional `ControlPluginContribution.validator` installed by `registerPlugin`; `getFieldValidator` / `hasFieldValidator` fall back after built-in `validatorsMap`; host `getValidator`; sample rejects angle brackets. Same preload path as IO hooks.
- **2026-08-07** — Plugin control IO hooks: `ControlPluginContribution.valueRetriever` / `valueSerializer` installed by `registerPlugin`, looked up after built-in maps in `valueRetrievers` / `valueSerializers`. Form bootstrap + save preload plugin locators via `preloadControlPluginsForFields` so hooks exist before parse/serialize. Host: `craftercms.formsEngine.controls.getValueRetriever` / `getValueSerializer`. Sample updated.
- **2026-08-06** — Controls cleanup (`7418`): retired unused `link-input` / `link-textarea` / `linked-dropdown` from FE2 maps + TB descriptors. Closed the former “non-rendering control-map entries” open item: those three are removed; `disabled` / `internal-name` remain TB catalog ids that remap on insert via `systemFieldsTypesMap` to `checkbox` / `input` (locked field ids). Documented under completed design decisions.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Synchronize the retired control entries with Open decisions.

Line 670 says link-input, link-textarea, and linked-dropdown were removed. It also says the former open item is closed. Line 654 still lists retired IDs and remapped aliases as unresolved. Update Line 654, or remove the entry if no null map slots remain, so the document has one completion status.

Proposed documentation fix
- - [ ] **Non-rendering control-map entries** — `disabled`, `internal-name`, `link-input`, `link-textarea` (and any other null map slots) need real FE2 controls or an explicit retire/alias decision.
+ - [ ] **Non-rendering control-map entries** — audit only remaining null map slots; `disabled` and `internal-name` remap on insertion, while `link-input`, `link-textarea`, and `linked-dropdown` are retired.

As per path instructions, update the Progress and Open decisions sections in studio-ui/docs/type-builder-forms-engine.md in the same effort.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@studio-ui/docs/type-builder-forms-engine.md` around lines 667 - 670,
Synchronize the Progress and Open decisions sections in the Forms Engine
documentation with the completed control cleanup: remove or mark resolved the
entries for retired IDs link-input, link-textarea, linked-dropdown and the
remapped disabled/internal-name aliases, ensuring no unresolved null-map-slot
item remains.

Source: Coding guidelines

Comment on lines +539 to +543
preloadControlPluginsForFields(siteId, contentType.fields)
.catch((error) => {
console.error('Failed to preload control plugins before create-form value parse.', error);
})
.then(initCreateForm);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Stop form initialization when control-plugin preload fails.

Both paths catch the preload rejection and then parse values without plugin hooks. This can load or save plugin field data with incorrect conversions.

  • studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx#L539-L543: set a preparation error and do not call initCreateForm after preload failure.
  • studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx#L586-L621: set a preparation error and do not call createParsedValuesObject after preload failure.
📍 Affects 1 file
  • studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx#L539-L543 (this comment)
  • studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx#L586-L621
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx` around lines 539
- 543, In studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx:539-543,
update the preload promise handling around initCreateForm to set the preparation
error and prevent initCreateForm from running when
preloadControlPluginsForFields fails. Apply the same behavior in
studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx:586-621: set the
preparation error and do not call createParsedValuesObject after preload
failure; retain the existing success paths.

Comment on lines +539 to +546
preloadControlPluginsForFields(siteId, contentType.fields)
.catch((error) => {
console.error('Failed to preload control plugins before create-form value parse.', error);
})
.then(initCreateForm);
return () => {
disposed = true;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preload plugins for embedded child forms.

The embedded-component branch at Lines 443-478 calls prepareEmbeddedItemForm before either preload path runs. If that component content type uses a plugin control that is not also present in the parent field tree, its hooks are unavailable during value parsing and validation.

Preload the embedded content type fields before invokePrepareFn parses them.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@studio-ui/ui/app/src/components/FormsEngine/FormsEngine.tsx` around lines 539
- 546, Update the embedded-component initialization flow around
prepareEmbeddedItemForm and invokePrepareFn so the embedded content type’s
fields are preloaded before invokePrepareFn parses or validates values. Reuse
the existing preloadControlPluginsForFields mechanism, awaiting or chaining it
before invokePrepareFn, while preserving the current parent-field preload and
initCreateForm behavior.

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