Add Tiptap rich text editor form type (TextEditorType)#121
Merged
Conversation
Coverage Report for CI Build 27538745215Warning No base build found for commit Coverage: 20.264%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats
💛 - Coveralls |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a reusable, progressively-enhanced Tiptap rich text editor Symfony form type (TextEditorType) with server-side sanitization/validation, plus the supporting UI (Stimulus controller, styles, Twig theme) and documentation.
Changes:
- Introduces
TextEditorTypewith server-side HTML sanitization and optional ProseMirror JSON validation. - Adds toolbar presets (
ToolbarPreset) as a shared source of truth for UI features and server allow-lists. - Adds frontend controller + styling + docs and wires required dependencies.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Bundle/PlatformBundle/Form/Type/TextEditorTypeTest.php | Adds coverage for HTML sanitization, JSON validation, and option validation for TextEditorType. |
| tests/Bundle/PlatformBundle/Form/TextEditor/ToolbarPresetTest.php | Adds coverage for preset feature lists and derived allow-lists. |
| src/Bundle/Platform/Resources/views/Form/theme.html.twig | Adds text_editor_widget Twig block rendering toolbar + editor container + backing textarea. |
| src/Bundle/Platform/Form/Type/TextEditorType.php | New form type wiring toolbar presets + transformers and exposing view vars for the widget/controller. |
| src/Bundle/Platform/Form/TextEditor/ToolbarPreset.php | Defines minimal/default/full presets and derives allowed HTML tags / PM nodes / marks / heading levels. |
| src/Bundle/Platform/Form/TextEditor/HtmlSanitizerFactory.php | Provides opinionated HtmlSanitizer configuration and per-preset element allow-listing. |
| src/Bundle/Platform/Form/DataTransformer/SanitizeHtmlTransformer.php | Sanitizes submitted HTML server-side (security boundary). |
| src/Bundle/Platform/Form/DataTransformer/JsonDocumentTransformer.php | Validates/sanitizes submitted ProseMirror JSON (node/mark allow-lists + link safety). |
| docs/index.md | Adds docs index link for “Form Types”. |
| docs/form-types/index.md | New index page for reusable form types. |
| docs/form-types/text-editor.md | Documents TextEditorType usage, options, build steps, and rendering guidance. |
| composer.json | Adds symfony/html-sanitizer dependency. |
| assets/scss/platform.scss | Imports the new text editor styles. |
| assets/scss/_text-editor.scss | Adds Bootstrap/Tabler-aligned rich editor styling. |
| assets/package.json | Registers text-editor Stimulus controller and adds Tiptap dependencies. |
| assets/controllers/text_editor_controller.ts | Adds Stimulus controller mounting Tiptap, wiring toolbar commands, syncing textarea, and cleanup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.
Summary
Adds a secure, opinionated Tiptap-based rich text editor form type (
TextEditorType) that any application can use to progressively enhance a standard textarea.Rich text editor (
TextEditorType)Form/Type/TextEditorType.php— extendsTextareaTypeso it degrades gracefully without JavaScript. Auto-registered via the bundle's existingservices.php. Options:output_format:html(default, sanitized HTML string) orjson(validated Tiptap/ProseMirror document)json_as_array: store JSON as a decoded PHP array or a JSON stringtoolbar:minimal/default/fullpresetallowed_tags,sanitizer,placeholder,editor_heightForm/TextEditor/ToolbarPreset.php— single source of truth mapping each preset to its toolbar buttons and sanitization allow-lists (HTML tags, ProseMirror nodes/marks, heading levels), so the UI and the server filter can't drift apart.Form/TextEditor/HtmlSanitizerFactory.php— opinionatedHtmlSanitizerconfig (safe link schemes only, forcedrel="noopener noreferrer").Form/DataTransformer/SanitizeHtmlTransformer.php— sanitizes submitted HTML on the server (the real security boundary).Form/DataTransformer/JsonDocumentTransformer.php— validates/sanitizes Tiptap JSON, rejecting disallowed nodes/marks/heading levels and stripping unsafe link URLs.Frontend
assets/controllers/text_editor_controller.ts— Stimulus controller mounting Tiptap (StarterKit + Link + Placeholder), wiring server-rendered toolbar buttons to editor commands, syncing content back into the hidden textarea, with Turbo-safe cleanup.assets/scss/_text-editor.scss— Tabler/Bootstrap-matched styling for the toolbar and.ProseMirrorcontent area (imported inplatform.scss).text-editorcontroller registered inassets/package.json.Twig, docs & deps
text_editor_widgetblock added to the platform form theme.docs/form-types/{index,text-editor}.md(linked fromdocs/index.md), including how to register the form theme and render the output safely.symfony/html-sanitizeradded tocomposer.json.Security
Sanitization happens in a Symfony data transformer — on the server, independent of the editor — so payloads that bypass the JavaScript editor cannot inject scripts, event handlers, or unsafe URL schemes. Links are restricted to
http/https/mailtoand forced to carryrel="noopener noreferrer".Testing
TextEditorTypeTestandToolbarPresetTest— 20 tests / 51 assertions passing, covering HTML sanitization, output formats, JSON validation/rejection, and option validation.