Design Patterns & Integration
Design patterns, integration points, data flow, and extension mechanisms for the RTE CKEditor Image extension.
Table of Contents
Overview
This document explains the design patterns, integration approaches, and data flow used in the RTE CKEditor Image extension. For system architecture and components, see System Architecture.
Key Design Patterns
The extension employs several proven design patterns for maintainability and extensibility:
- MVC Pattern - Controllers, models, and views separation
- Event-Driven - PSR-14 events for extensibility
- Plugin Architecture - Modular CKEditor plugin
- Soft References - TYPO3 reference tracking
- Command Pattern - CKEditor commands for actions
Dependency Injection
All PHP classes use Symfony's dependency injection:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
This approach provides:
- Loose coupling between components
- Easier testing through dependency substitution
- Clear component dependencies
- Automatic service wiring
Event-Driven Architecture
TYPO3 event system for loose coupling:
AfterPrepareConfigurationForEditorEvent
- RTE configuration- TCEmain hooks for data processing
Benefits:
- Components can be extended without modification
- Third-party extensions can hook into processing
- Maintainable separation of concerns
- Clear extension points for customization
MVC Pattern
Controllers handle requests, models represent data, views render output:
- Controllers: Process backend requests and coordinate actions
- FAL Models: Represent files and their metadata
- TypoScript Views: Render frontend HTML output
This separation ensures:
- Clear responsibility boundaries
- Independent testing of each layer
- Flexible view rendering strategies
- Reusable business logic
Plugin Pattern
CKEditor 5 plugin system:
- Custom
typo3image
model element - Editor commands and UI components
- Conversion system for data transformation
Implementation details:
- Plugin registration via
Plugin.yaml
- Custom schema definitions for model elements
- Bidirectional conversion (upcast/downcast)
- Integration with CKEditor's command system
Integration Points
TYPO3 Core Integration
-
RTE CKEditor: Extends TYPO3's CKEditor integration
- Registers custom plugin through YAML configuration
- Extends default RTE configuration
- Adds TYPO3-specific functionality to editor
-
FAL: Uses File Abstraction Layer for file management
- Leverages FAL for unified file handling
- Respects file permissions and access rights
- Supports all FAL storage drivers
- Maintains file reference integrity
-
TCEmain: Hooks into data processing pipeline
- Processes image references during save operations
- Updates soft references automatically
- Validates data integrity
- Triggers reference index updates
-
Soft References: Tracks file references for integrity
- Custom soft reference parser for RTE images
- Enables reference tracking across content
- Supports reference index operations
- Prevents orphaned file records
CKEditor Integration
-
Plugin Registration: Via JavaScriptModules.php and Plugin.yaml
- Module registration in PHP
- Plugin configuration in YAML
- Integration with TYPO3's asset management
- Proper loading order and dependencies
-
Custom Model:
typo3image
element with TYPO3-specific attributes- Schema definition for element structure
- Support for data-htmlarea-* attributes
- Custom properties for FAL integration
- Validation rules for data integrity
-
Style System: Integration with CKEditor's style drop-down
- Custom style definitions
- Integration with GeneralHtmlSupport
- TYPO3-specific class handling
- Style persistence in content
-
Conversion: Bidirectional HTML ↔ Model conversion
- Upcast: HTML to model during editor initialization
- Downcast: Model to HTML during save operations
- Attribute mapping and transformation
- Special handling for TYPO3 data attributes
Data Flow
Image Selection Flow
User clicks insert image
↓
CKEditor plugin opens modal
↓
Backend route loads file browser
↓
User selects image
↓
JavaScript receives file UID
↓
Backend API returns image info
↓
Dialog opens with image properties
↓
User confirms settings
↓
typo3image model element created
↓
Content saved to database
Detailed steps:
- User Interaction: Editor toolbar button clicked
- Modal Opening: CKEditor executes custom command
- Browser Loading: AJAX call to backend route
- File Selection: User navigates FAL structure
- Data Retrieval: File UID sent to backend API
- Properties Dialog: JavaScript populates form with file data
- Confirmation: User sets dimensions, alignment, etc.
- Model Creation: CKEditor creates typo3image element
- Persistence: Content saved with data-htmlarea-* attributes
Frontend Rendering Flow
RTE content loaded from database
↓
lib.parseFunc_RTE processes content
↓
ImageRenderingController hook invoked
↓
FAL file loaded from UID
↓
Magic image processing applied
↓
Processed image URL generated
↓
HTML with processed URL rendered
↓
Internal data-* attributes removed
Detailed steps:
- Content Retrieval: Database query loads RTE field
- TypoScript Processing: lib.parseFunc_RTE activated
- Hook Execution: Custom rendering hook triggered
- File Loading: FAL resolves file UID to file object
- Image Processing: Magic image generation (resize, crop, etc.)
- URL Generation: Processed image URL created
- HTML Rendering: Final img tag generated
- Attribute Cleanup: Internal data-* attributes stripped
Extension Points
Developers can extend the extension through:
-
Event listeners (PSR-14 events)
AfterPrepareConfigurationForEditorEvent
: Customize RTE configuration- Custom events can be added for additional hooks
- Event priority allows fine-grained control
- Standard TYPO3 event dispatcher patterns
-
TypoScript configuration
- Override rendering settings
- Custom image processing instructions
- Template modifications
- Additional CSS classes or attributes
-
XClasses (not recommended)
- Last resort for core modifications
- Potential compatibility issues
- Better alternatives usually exist
- Should only be used when no other option available
-
Custom processing hooks
- TCEmain hooks for data manipulation
- Content element rendering hooks
- Custom transformations during save/load
- Validation and sanitization extensions
-
Additional CKEditor plugins
- Complementary functionality
- Integration with typo3image plugin
- Custom commands and UI components
- Extended model attributes
Example Event Listener
use TYPO3\CMS\RteCKEditor\Form\Element\Event\AfterPrepareConfigurationForEditorEvent;
class CustomRteConfigurationListener
{
public function __invoke(AfterPrepareConfigurationForEditorEvent $event): void
{
$config = $event->getConfiguration();
// Modify configuration as needed
$config['typo3image']['customSetting'] = 'value';
$event->setConfiguration($config);
}
}
Example TypoScript Extension
lib.parseFunc_RTE {
tags {
img {
width = 1920
height = 1080
// Custom processing
params = class="custom-image-class"
}
}
}